Page 1 of 1
makeRDF script
Posted: Thu Mar 13, 2003 6:40 pm
by tariqali
hi,
I am trying to use this script to create rdf file for my site.
http://www.phpdeveloper.org/our_scripts.php?script_id=2
I modifed for my database connection and my site profile but still it doesn't work. I chmod the path where my rdf file is in but nothing happen when I load the script.
I ftp to my rdf file and it was empty.
Is there something special I should do to make it work? I am loading the script by pointing my browser to the makerdf.php file.
Thanks.
Posted: Thu Mar 13, 2003 6:49 pm
by volka
maybe you should increase the reporting level and let php display errors in the browser while developing the script, e.g. via
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
class RDF{
...
?>
if still nothing(!) shows up there's probably a parse error in your script.
php -l <path.to.script> checks that for you
Posted: Thu Mar 13, 2003 7:20 pm
by tariqali
Thanks for the quick reply.
I tried the code to display the error on the page but that didn't display anything for me.
I didn't really understand what you said about the "parse error " Also, I don't really know much about php beside installing scripts and very minor modifications.
Posted: Fri Mar 14, 2003 4:48 am
by volka
before the script is executed it must be parsed. Now if you have something like
Code: Select all
<?php
if (TRUE)
{
echo 'trivial';
?>
you have a parse error, because a } is missing.
Code: Select all
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ?>
cannot enable the output of this kind of error, because it would take action after the file is parsed (which can't be done). But there are (at least) two ways to change these values before(!) the file is parsed.
If it is a development system only and you have access to php.ini you might want to set
php.ini wrote:; Examples:
;
; - Show all errors, except for notices
;
;error_reporting = E_ALL & ~E_NOTICE
;
; - Show only errors
;
;error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
;
; - Show all errors
;
error_reporting = E_ALL
; Print out errors (as a part of the output). For production web sites,
; you're strongly encouraged to turn this feature off, and use error logging
; instead (see below). Keeping display_errors enabled on a production web site
; may reveal security information to end users, such as file paths on your Web
; server, your database schema or other information.
display_errors = On
; Even when display_errors is on, errors that occur during PHP's startup
; sequence are not displayed. It's strongly recommended to keep
; display_startup_errors off, except for when debugging.
display_startup_errors = On
This affects all scripts on that server.
If you do not have access to php.ini or do not want to change the behaviour of all scripts you might place a .htaccess in the directory of the script(s) you want to test (if you're using a webserver that supports .htaccess) and add
Code: Select all
php_value error_reporting E_ALL
php_flag display_errors On
php_flag display_startup_errors On
to it.
If php is installed as module and you've changed php.ini you probably have to restart the server.
Posted: Fri Mar 14, 2003 5:48 pm
by tariqali
Non of that worked. I edited my .htacess and nothing happen when I load the script.
Here is the code after I modifed it to fit my site:
Code: Select all
<?php
class RDF{
function makeHeader($title,$link,$desc,$img){
$info.="<?xml version="1.0"?>\n\n";
$info.="<rdf:RDF\nxmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\nxmlns="http://my.netscape.com/rdf/simple/0.9/">\n\n";
$info.="<channel>\n<title>".$title."</title>\n";
$info.="<link>".$link."</link>\n<description>".$desc."</description>\n</channel>\n\n";
$info.="<image>\n<title>".$title."</title>\n<url>".$img."</url>\n<link>".$link."</link>\n</image>\n\n";
return $info;
}
function makeFooter(){
$info.="</rdf:RDF>\n";
return $info;
}
function getStories(){
$sql="select link_id, link_name from links ORDER BY link_date DESC LIMIT 10";
$db=mysql_connect("localhost","user","pass") or die ("cant connect");
mysql_select_db("myDatabasename",$db) or die ("cant change");
$news=mysql_query($sql) or die ("cant get em");
while($rows=mysql_fetch_array($news)){
$info.="<item>\n<title>".htmlspecialchars($rowsї"link_name"])."</title>\n<link>http://www.mysite.com/index.php?id=".$rowsї"link_id"]."</link>\n</item>\n\n";
}
return $info;
}
function writeRDF($filename, $content){
$fp=fopen($filename,"w+");
fwrite($fp,$content);
fclose($fp);
}
function makeRDF(){
$title="mysite.com";
$link="http://www.mysite.com/";
$desc="Just testing";
$img="http://www.mysite.com/images/logo.gif";
$filename="rss.rdf";
$content=$this->makeHeader($title, $link, $desc,$img);
$content.=$this->getStories();
$content.=$this->makeFooter();
//echo $content;
echo "Added to RDF successfully!";
$this->writeRDF($filename, $content);
}
/*end class*/
}
?>
Do you see anything wrong with it

Posted: Fri Mar 14, 2003 5:58 pm
by volka
did you create an instance of that class and called at least one method of it?
Code: Select all
<?php
class RDF{
...
}
$r = new RDF;
$->makeRDF();
?>
Posted: Fri Mar 14, 2003 8:51 pm
by tariqali
All I did is create a file in my server called makeRDF.php and copy and past the above script after modifying my server info.
Is there something else I need to do beside that?
Posted: Sat Mar 15, 2003 4:03 am
by volka
Code: Select all
<?php
class RDF{
...
}
$r = new RDF; // create new instance/object
$->makeRDF(); // call a method for this object
?>
a class (in php) is merely a definition, like functions are.
You have to invoke them to get them executed. And since makeRDF uses
$this-> you need an instance of the class before you can call makeRDF().
read
http://www.php.net/manual/en/language.oop.php to learn a bit more about it.