makeRDF script
Moderator: General Moderators
makeRDF script
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.
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.
maybe you should increase the reporting level and let php display errors in the browser while developing the script, e.g. viaif still nothing(!) shows up there's probably a parse error in your script.
php -l <path.to.script> checks that for you
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
class RDF{
...
?>php -l <path.to.script> checks that for you
http://www.php.net/manual/en/features.commandline.php wrote:Usage: php [options] [-f] <file> [args...]
...
-l Syntax check only (lint)
before the script is executed it must be parsed. Now if you have something likeyou have a parse error, because a } is missing.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
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 addto it.
If php is installed as module and you've changed php.ini you probably have to restart the server.
Code: Select all
<?php
if (TRUE)
{
echo 'trivial';
?>Code: Select all
<?php error_reporting(E_ALL); ini_set('display_errors', TRUE); ?>If it is a development system only and you have access to php.ini you might want to set
This affects all scripts on that server.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
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 OnIf php is installed as module and you've changed php.ini you probably have to restart the server.
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:
Do you see anything wrong with it 
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*/
}
?>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();
?>Code: Select all
<?php
class RDF{
...
}
$r = new RDF; // create new instance/object
$->makeRDF(); // call a method for this object
?>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.