Foros del Web » Programando para Internet » PHP »

porque no me rula este codigo?

Estas en el tema de porque no me rula este codigo? en el foro de PHP en Foros del Web. Hola pues nada que necesito convertir ha RSS las noticias de mi web,me recomendaron que buscara en hotscripts,y encontre uno muy bueno,pero que no se ...
  #1 (permalink)  
Antiguo 22/12/2005, 10:38
Avatar de Diabolus  
Fecha de Ingreso: diciembre-2004
Mensajes: 453
Antigüedad: 19 años, 4 meses
Puntos: 0
porque no me rula este codigo?

Hola pues nada que necesito convertir ha RSS las noticias de mi web,me recomendaron que buscara en hotscripts,y encontre uno muy bueno,pero que no se porque no funciona!:(.....
He cambiado los datos y todo lo necesario pero no me anda....porque?

Gracias,aqui os dejo el codigo ^^:
Código PHP:
<?php
/*
 Project:     playRSSwriter: RSS 2.0 writer with images support
 File:        playRSSwriter.php
 Author:      Eduardo Perez Orue <[email protected]>
 Version:     0.90

 For the latest version of the writer, questions, help, comments, 
 etc., please visit:
 http://hombrelobo.com/rss/playrsswriter.htm

 You can download the script here:
 http://playlingerie.com/playrsswriter/playRSSwriter.php.txt

 What is playRSSwriter ? 
 When working on creating a rss feed for our site http://playlingerie.com, 
 we realized that all the existing php writers were either for rss 1.0 or for 
 rss 2.0 but without support for embeded images. So I created this code. 
 You can see it in action in:
 http://playlingerie.com/rss.php           (machines) or
 http://feeds.feedburner.com/sexy-lingerie (humans)
 
 Enjoy it !!

 ******************************************************************************
 This program is distributed in the hope that it will be useful, but 
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 or FITNESS FOR A PARTICULAR PURPOSE.

 This work is hereby released into the Public Domain. To view a copy of
 the public domain dedication, visit 
 http://creativecommons.org/licenses/publicdomain/ or send a letter to
 Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
 ******************************************************************************
 */

// First we start defining all the variables that we will insert in the 
// xml code. 

// Insert here the the title of your feed
$rss_title"Title of your feed";  
// Insert your site, in the format site.com
$rss_site"site.com" ;
// Insert the description of your website
$rss_description"Description of your website";
// Applicable language of the feed. For spanish, change to "es"
$rss_language="en";                     
// Address of the logo file. Only need to put the file name
$rss_logo="http://".$rss_site."logo.jpg";  
// the feed's author email
$emailadmin="[email protected]";   

// set the file's content type and character set
// this must be called before any output
header("Content-Type: text/xml;charset=iso-8859-1");

$phpversion phpversion();

//set the beginning of the xml file
ECHO <<<END
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
    <channel>
      <title>$rss_title</title>
      <link>http://www.$rss_site</link>
      <description>$rss_description</description>
      <language>$rss_language-$rss_language</language>
      <docs>http://backend.userland.com/rss</docs>
      <generator>PHP/$phpversion</generator>
    <image>
<url>$rss_logo</url>
<title>$rss_site</title>
<link>http://$rss_site/</link>
</image>
END;

// Now the variables about the individual items to appear in the feed. Here we 
// take them from a MySQL database, but can also come from a included file

// Define database

$server "localhost";                                  // Server
$rss_database "name_of_the_database" ;            // Database name
$db_user ="user" ;                                          // Database user
$db_pass "password" ;                                      // Database password

// Open the database

$db mysql_connect($server,$db_user,$db_pass);        
mysql_select_db($rss_database,$db);

// Calculate the number of records in the table "Products"

$num_rows mysql_num_rows(mysql_query("select * from Products"));  

// Select all the records from the table "Products". You can modify the
// query to only select some records, change the order, etc.

$query "select * from Products" ;
$result mysql_query($query) or die("Query failed") ;

//Make a loop to create the feed for all the items selected                                                

while ($results mysql_fetch_array($result)) 
  {

// Pass the database field Photo_name to the variable $photo_name                                                
// The Photo_name has to include the relative path, 
// for instance: $photo_name="images/photo1.jpg";

$photo_name $results['Photo_name'] ;     

// Pass the record URL_product to the variable $url_product. It also 
// has to include the relative path, like in: "path/product1.htm"

$url_product $results['URL_product'] ;

// Pass the record Description to the variable $description

$description $results['Description'] ;

// Clean the description

$description str_replace ("&","",htmlspecialchars(stripslashes($description)));

// Pass tags to describe the product 

$rss_tags $results['Product_tags'] ;     
  
// If you don't have tags for the product, simply change to a fixed value,
// for instance put: 
// $rss_tags="tag1 tag2";

// Make a short description for titles of only 75 characters

$short_description substr($description,0,75) . "...";

$counter ++ ;

// Calculate the size of the image and resize it to a thumbnail

$photo_sizegetimagesize($photo_name) ;
$photo_width $photo_size[0] ;
$photo_height $photo_size[1] ;
unset(
$height_limit,$width_limit) ;

if (
$photo_height $photo_width )
    
$photo_height"90" ;
else
    
$photo_width "80" ;

// Create the html for the description item. No need to modify this unless
// you want to change the look

$content="<p><a href=\"http://$rss_site/$url_product\">$description</a></p>
<p><a href=\"http://$rss_site/$url_product\" title=\"$description\"><img src=\"$photo_name\" width=\"$photo_width\" height=\"$photo_height\" alt=\"$short_description\" style=\"border: 1px solid #000000;\" /></a></p>
<p>$rss_site</p>" 
;

// Escape all the descriptions

$content preg_replace(array('/</''/>/''/"/'), array('<''>''"'), $content);

// display an item

ECHO <<<END
    <item>
<title>$short_description</title>
    <link>
http://$rss_site/$url_product
</link>
    <description>
$content
</description>
<author>$emailadmin</author>
<media:content url="$photo_name" type="image/jpeg" height="$photo_height" width="$photo_width"/>
<media:title>$description</media:title>
    <media:text type="html">
<p><a href="http://$rss_site/$url_product">$description</a></p>
<p><a href="http://$rss_site/$url_product" title="$short_description"><img src="$photo_name" width="$photo_width" height="$photo_height" alt="$short_description" style="border: 1px solid #000000;" /></a></p>
<p>$rss_site</p>
</media:text>
<media:thumbnail url="$photo_name" height="$photo_height" width="$photo_width"/>
    <media:category scheme="urn:$rss_site:tags">
$rss_tags
</media:category>
</item>
END;
 
  } 

// Close the database

mysql_close();

// And end the xml file

ECHO <<<END
   </channel>
</rss>
END;

// Done !!  Use http://feedvalidator.com to verify that it's correct.
?>
  #2 (permalink)  
Antiguo 22/12/2005, 10:47
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues si tu que lo has probado no llegas a ver algún mensaje de error o por lo menos nos describes como lo pretenes usar y/o que hace cuando lo ejecutas .. mm es como complicado decirte en -tu caso concreto- por qué no te funciona ..

Un saludo,
  #3 (permalink)  
Antiguo 22/12/2005, 16:14
Avatar de Diabolus  
Fecha de Ingreso: diciembre-2004
Mensajes: 453
Antigüedad: 19 años, 4 meses
Puntos: 0
si,perdon siempre con las prisas.....si es que con las prisas no llegare a ningun lado!!!....perdon bueno hago lo siguiente,cambio los parametros de la BD,y lo guardo como archivo "rss.php",y lo ejecuto desde localhost/rss.php bien me dice esto:
Parse error: parse error, unexpected T_SL, expecting ',' or ';' in c:\appserv\www\rss.php on line 60

creo que dice que falta una coma o algo....los errores en php nunca se me dieron bien....:(
  #4 (permalink)  
Antiguo 23/12/2005, 05:13
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Indicanos cual es el código de la línea 60 y pon el código que uses tu concretamente con tus cambios realizados. (no el ejemplo que tomastes .. sino lo que te quedó tras tu edición).

Como bien dices .. algun ; parece que te has dejado por ahí ..

Un saludo,
  #5 (permalink)  
Antiguo 23/12/2005, 07:00
Avatar de Diabolus  
Fecha de Ingreso: diciembre-2004
Mensajes: 453
Antigüedad: 19 años, 4 meses
Puntos: 0
ok,mira este es el codigo que modifique:
Código PHP:
<?php 
/* 
 Project:     playRSSwriter: RSS 2.0 writer with images support 
 File:        playRSSwriter.php 
 Author:      Eduardo Perez Orue <[email protected]
 Version:     0.90 

 For the latest version of the writer, questions, help, comments,  
 etc., please visit: 
 http://hombrelobo.com/rss/playrsswriter.htm 

 You can download the script here: 
 http://playlingerie.com/playrsswriter/playRSSwriter.php.txt 

 What is playRSSwriter ?  
 When working on creating a rss feed for our site http://playlingerie.com,  
 we realized that all the existing php writers were either for rss 1.0 or for  
 rss 2.0 but without support for embeded images. So I created this code.  
 You can see it in action in: 
 http://playlingerie.com/rss.php           (machines) or 
 http://feeds.feedburner.com/sexy-lingerie (humans) 
  
 Enjoy it !! 

 ****************************************************************************** 
 This program is distributed in the hope that it will be useful, but  
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  
 or FITNESS FOR A PARTICULAR PURPOSE. 

 This work is hereby released into the Public Domain. To view a copy of 
 the public domain dedication, visit  
 http://creativecommons.org/licenses/publicdomain/ or send a letter to 
 Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. 
 ****************************************************************************** 
 */ 

// First we start defining all the variables that we will insert in the  
// xml code.  

// Insert here the the title of your feed 
$rss_title"Title of your feed";   
// Insert your site, in the format site.com 
$rss_site"localhost" 
// Insert the description of your website 
$rss_description"Description of your website"
// Applicable language of the feed. For spanish, change to "es" 
$rss_language="es";                      
// Address of the logo file. Only need to put the file name 
$rss_logo="http://".$rss_site."logo.jpg";   
// the feed's author email 
$emailadmin="[email protected]";    

// set the file's content type and character set 
// this must be called before any output 
header("Content-Type: text/xml;charset=iso-8859-1"); 

$phpversion phpversion(); 

//set the beginning of the xml file 


ECHO <<<END // esta es la linea que me molesta


<? xml version="1.0" encoding="iso-8859-1"?> 
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss"> 
    <channel> 
      <title>$rss_title</title> 
      <link>http://www.$rss_site</link> 
      <description>$rss_description</description> 
      <language>$rss_language-$rss_language</language> 
      <docs>http://backend.userland.com/rss</docs> 
      <generator>PHP/$phpversion</generator> 
    <image> 
<url>$rss_logo</url> 
<title>$rss_site</title> 
<link>http://$rss_site/</link> 
</image> 
END;

// Now the variables about the individual items to appear in the feed. Here we  
// take them from a MySQL database, but can also come from a included file 

// Define database 

$server = "localhost";                                  // Server 
$rss_database = "test" ;            // Database name 
$db_user ="Mysql" ;                                          // Database user 
$db_pass = "" ;                                      // Database password 

// Open the database 

$db = mysql_connect($server,$db_user,$db_pass);         
mysql_select_db($rss_database,$db); 

// Calculate the number of records in the table "noticias" 

$num_rows = mysql_num_rows(mysql_query("select * from noticias"));   

// Select all the records from the table "noticias". You can modify the 
// query to only select some records, change the order, etc. 

$query = "select * from noticias" ; 
$result = mysql_query($query) or die("Query failed") ; 

//Make a loop to create the feed for all the items selected                                                 

while ($results = mysql_fetch_array($result))  
  { 

// Pass the database field Photo_name to the variable $photo_name                                                 
// The Photo_name has to include the relative path,  
// for instance: $photo_name="images/photo1.jpg"; 

$photo_name = $results['Photo_name'] ;      

// Pass the record URL_product to the variable $url_product. It also  
// has to include the relative path, like in: "path/product1.htm" 

$url_product = $results['URL_product'] ; 

// Pass the record Description to the variable $description 

$description = $results['Description'] ; 

// Clean the description 

$description = str_replace ("&","",htmlspecialchars(stripslashes($description))); 

// Pass tags to describe the product  

$rss_tags = $results['Product_tags'] ;      
   
// If you don't have tags for the product, simply change to a fixed value, 
// for instance put:  
// $rss_tags="tag1 tag2"; 

// Make a short description for titles of only 75 characters 

$short_description = substr($description,0,75) . "..."; 

$counter ++ ; 

// Calculate the size of the image and resize it to a thumbnail 

$photo_size= getimagesize($photo_name) ; 
$photo_width = $photo_size[0] ; 
$photo_height = $photo_size[1] ; 
unset($height_limit,$width_limit) ; 

if ($photo_height > $photo_width ) 
    $photo_height= "90" ; 
else 
    $photo_width = "80" ; 

// Create the html for the description item. No need to modify this unless 
// you want to change the look 

$content="<p><a href=\"http://$rss_site/$url_product\">$description</a></p> 
<p><a href=\"http://$rss_site/$url_product\" title=\"$description\"><img src=\"$photo_name\" width=\"$photo_width\" height=\"$photo_height\" alt=\"$short_description\" style=\"border: 1px solid #000000;\" /></a></p> 
<p>$rss_site</p>" ; 

// Escape all the descriptions 

$content = preg_replace(array('/</', '/>/', '/"/'), array('<', '>', '"'), $content); 

// display an item 

ECHO <<<END 
    <item> 
<title>$short_description</title> 
    <link> 
http://$rss_site/$url_product 
</link> 
    <description> 
$content 
</description> 
<author>$emailadmin</author> 
<media:content url="$photo_name" type="image/jpeg" height="$photo_height" width="$photo_width"/> 
<media:title>$description</media:title> 
    <media:text type="html"> 
<p><a href="http://$rss_site/$url_product">$description</a></p> 
<p><a href="http://$rss_site/$url_product" title="$short_description"><img src="$photo_name" width="$photo_width" height="$photo_height" alt="$short_description" style="border: 1px solid #000000;" /></a></p> 
<p>$rss_site</p> 
</media:text> 
<media:thumbnail url="$photo_name" height="$photo_height" width="$photo_width"/> 
    <media:category scheme="urn:$rss_site:tags"> 
$rss_tags 
</media:category> 
</item> 
END;
  
  }  

// Close the database 

mysql_close(); 

// And end the xml file 

ECHO <<<END 
   </channel> 
</rss> 
END;

// Done !!  Use http://feedvalidator.com to verify that it's correct. 
?>
Esta es la linea:
ECHO <<<END


gracias ;)
  #6 (permalink)  
Antiguo 23/12/2005, 09:30
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Ese:

ECHO <<<END

está al principio de esa línea? sin ningún espacio por delante? .. lo mismo que el: END; .. (deben estar al principio de la línea que esten). Podría estar el problema por ahí, por cierto ese tipo de sintax le llaman "Here Doc":

http://www.php.net/manual/en/languag...syntax.heredoc

También ten cuidado (aunque no debería afectar):
$rss_site= "localhost" ;
usa:
$rss_site= "localhost"; // sin espacios despues de la última instrucción o string.

Un saludo,
  #7 (permalink)  
Antiguo 23/12/2005, 10:26
Avatar de Diabolus  
Fecha de Ingreso: diciembre-2004
Mensajes: 453
Antigüedad: 19 años, 4 meses
Puntos: 0
mira hay esto antes y despues del end ^^

Código PHP:
header("Content-Type: text/xml;charset=iso-8859-1");  

$phpversion = phpversion();  

//set the beginning of the xml file  


ECHO <<<END // esta es la linea que me molesta 


<? xml version="1.0" encoding="iso-8859-1"?>  
<rss version="2.0" xmlns:media="http://search.yahoo
miro lo de localhost ^^
  #8 (permalink)  
Antiguo 26/12/2005, 04:57
Avatar de hombrelobo  
Fecha de Ingreso: agosto-2005
Mensajes: 54
Antigüedad: 18 años, 7 meses
Puntos: 0
Hola, el código s mío, y estoy encantado de que lo uses.

¿ Porqué no nos dejas ver el código xml resultante ? Una buena opción es también utilizar http://feedvalidator.org para comprobar los errores.

Y si tienes más problemas, envíame un mensaje privado, y te lo miro.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:40.