makeRDF script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tariqali
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2003 6:40 pm

makeRDF script

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
http://www.php.net/manual/en/features.commandline.php wrote:Usage: php [options] [-f] <file> [args...]
...
-l Syntax check only (lint)
tariqali
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2003 6:40 pm

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
tariqali
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2003 6:40 pm

Post 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&#123;
    function makeHeader($title,$link,$desc,$img)&#123;
        $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;
    &#125;

    function makeFooter()&#123;
        $info.="</rdf:RDF>\n";
        return $info;
    &#125;

    function getStories()&#123;
        $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))&#123;
            $info.="<item>\n<title>".htmlspecialchars($rows&#1111;"link_name"])."</title>\n<link>http://www.mysite.com/index.php?id=".$rows&#1111;"link_id"]."</link>\n</item>\n\n";
        &#125;
        return $info;
    &#125;

    function writeRDF($filename, $content)&#123;
        $fp=fopen($filename,"w+");
        fwrite($fp,$content);
        fclose($fp);
    &#125;

    function makeRDF()&#123;
        $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);
    &#125;
/*end class*/
&#125;
?>
Do you see anything wrong with it :cry:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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();
?>
tariqali
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2003 6:40 pm

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
Post Reply