473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP to RSS

I'd like to create a simple RSS feed using some PHP code, e.g. displaying
the remote IP and Host name.
Who can help me with this ?

Thanks in advance,

Robertico

Sep 19 '06 #1
11 1660
You will need to set the header :
<?php
header("Content-Type: text/xml");
?>
the header has to be set in order to specify that you will be writing
xml.
When you want to print something like the ip do this:
<ipaddress><?php echo $_SESSION["IPADDRESS"];?></ipaddress>

After the header is set and you escape from php you'll just be creating
regular xml tags and printing using php when you need to....I hope that
helps

Daniel

Sep 19 '06 #2
Here is the script that I used to generate RSS 2.0 feed using PHP.
<?php

$href="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$logo="http://www.embedworld.com/images/top_logo.gif";
$title="Embedworld download center";
$link="http://en.embedworld.com";
$copyright="Copyright (c) 2004-2006 Embedworld.com All Rights
Reserved.";
$language="en";
$title="Embedworld.com";
$description="Embedworld.com, Embedded unit the world!";

// Don't edit the content below
if(function_exists("getimagesize")) {
list($width, $height, $type, $attr) = getimagesize($logo);
} else {
list($width, $height)= array(88, 31);
}

$lastBuildDate=date("r");

if(1) {

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");

header('Content-type: text/xml');
print "<?xml version=\"1.0\" encoding=\"gb2312\"?>";

print <<<HTML

<rss version="2.0">

<channel>

<title>$title</title>

<description>$description</description>

<copyright>$copyright</copyright>

<link>$link</link>

<language>$language</language>

<generator>Embedworld RSS Feed Generator 2.0</generator>

<lastBuildDate>$lastBuildDate</lastBuildDate>

<ttl>60</ttl>

<image>

<title>$title</title>

<width>$width</width>

<height>$height</height>

<link>$link</link>

<url>$logo</url>

</image>

HTML;

$dbtype="mysql";

include('./adodb471-1/adodb/adodb.inc.php');
if($dbtype == "mysql") {
$dbhost="localhost";
$dbname="test";
$dbport="3306";
$dbuser="root";
$dbpass="";

$dsn = "$dbtype://$dbuser:$dbpass@$dbhost/$dbname";
$db = NewADOConnection($dsn);
if (!$db) die("Connection failed");
}

if($dbtype == "access") {
//Access test here
$access="D:\\db_data.mdb";
$dbuser="";
$dbpass="";
$db =& ADONewConnection('access');
$dsn = "Driver={Microsoft Access Driver
(*.mdb)};Dbq=$access;Uid=$dbuser;Pwd=$dbpass;";
$db->Connect($dsn);
if (!$db) die("Connection failed");
}

///*
if(isset($query) && !empty($query)) {

$sql="select * from `db_class` where nsort ='down'";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs = $db->Execute($sql);
if ($rs) {
while (!$rs->EOF) {
$data=$rs->GetAssoc();
foreach ($data as $i =$value) {
$sql2="select * from `db_sort` where id =$i";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$rs2 = $db->Execute($sql2);
if ($rs2) {
while (!$rs2->EOF) {
$data2=$rs2->GetAssoc();
foreach ($data2 as $i2 =$value2) {

print <<<HTML
<item>

<title>ClassID: $i =$value </title>

<descriptionSub ClassID: $i2 =$value2</description>

</item>

HTML;
}
$rs2->MoveNext();
}
}
}
$rs->MoveNext();
}
} else {
print "<errorError <br /></error>\n";
} // End of else if ($rs)

unset($data, $sql, $i, $value);

print <<<HTML
</channel>
</rss>
HTML;

exit(0);
}


$cnt=0;

$sql="select * from `down` where $condition";
// print "<SQL[$sql] </SQL>\n";
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
// $db->debug = true;
$rs = $db->Execute($sql);
if ($rs) {
$data=$rs->GetRows();

foreach ($data as $dt) {

print <<<HTML
<item>

<title>$name</title>
<link>$url</link>
<description>$remark</description>
<pubDate>$tim</pubDate>
</item>

HTML;

} // End of foreach
} else {
print "Error<br />\n";
}// End of else if ($rs)

print <<<HTML
</channel>
</rss>
HTML;

} // End ...

?>

Hopefully it is helpful to you!

Regards,
Signal
From: http://en.embedworld.com
Cu************@gmail.com wrote:
You will need to set the header :
<?php
header("Content-Type: text/xml");
?>
the header has to be set in order to specify that you will be writing
xml.
When you want to print something like the ip do this:
<ipaddress><?php echo $_SESSION["IPADDRESS"];?></ipaddress>

After the header is set and you escape from php you'll just be creating
regular xml tags and printing using php when you need to....I hope that
helps

Daniel
Sep 20 '06 #3
Thanks Daniel and Andreas.

Must i save it as php or xml.
If it's xml. are there some modifications needed for my httpd.conf ?

Regards,

Robertico
Sep 20 '06 #4
NC
Robertico wrote:
>
Must i save it as php or xml.
PHP.

Cheers,
NC

Sep 20 '06 #5
I can't get i to work.
When i saved it as php file, the php code isn't executed.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>MyTitle</title>
<link>http://www.mydomain.com/</link>
<description>MYDescription</description>
<item>
<title>YourIP</title>
<link>http://www.mydomain.com/yourip.php</link>
<description>Your current IP</description>
<ipaddress><?php echo getenv ("REMOTE_ADDR");?></ipaddress>
</item>
</channel>
</rss>

So, i need i little more help.

Regards,

Robertico
Sep 22 '06 #6
I can't get i to work.
When i saved it as php file, the php code isn't executed.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>MyTitle</title>
<link>http://www.mydomain.com/</link>
<description>MYDescription</description>
<item>
<title>YourIP</title>
<link>http://www.mydomain.com/yourip.php</link>
<description>Your current IP</description>
<ipaddress><?php echo getenv ("REMOTE_ADDR");?></ipaddress>
</item>
</channel>
</rss>
What extension have your file?
..xml? or .php?

Support your server PHP or NOT?

Sep 22 '06 #7
NC
Robertico wrote:
>
I can't get i to work.
When i saved it as php file, the php code isn't executed.

<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>MyTitle</title>
<link>http://www.mydomain.com/</link>
<description>MYDescription</description>
<item>
<title>YourIP</title>
<link>http://www.mydomain.com/yourip.php</link>
<description>Your current IP</description>
<ipaddress><?php echo getenv ("REMOTE_ADDR");?></ipaddress>
</item>
</channel>
</rss>
OK, let's make a checklist:

1. Does your server execute code in other PHP scipts?

2. Is this script saved with a *.php extension?

3. What exactly do you see in the output that makes
you think PHP code is not executed?

4. What happens if you replace

<?xml version="1.0"?>

with

<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0"?>';
?>

Cheers,
NC

Sep 22 '06 #8
1. Does your server execute code in other PHP scipts?
- Yes
2. Is this script saved with a *.php extension?
- Yes
3. What exactly do you see in the output that makes you think PHP code is
not executed?
- My RSS reader (SharpReader, Feedreader) doesn't display the IP address
(php code). It displays only the description (tag).
4. What happens if you replace

<?xml version="1.0"?>

with

<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0"?>';
?>
- The same result in my RSS reader. (SharpReader, Feedreader)
- But when open it in a browser, it's xml formatted with the current IP
address between the <ipaddresstags.
So the php code is executed.
My RSS reader (SharpReader, Feedreader) doesn't display the IP address
(php code). It displays only the description (tag).
It seems that it can't handle the <ipaddresstag.

Regards,

Robertico
Sep 23 '06 #9
NC
Robertico wrote:
>
- The same result in my RSS reader. (SharpReader, Feedreader)
- But when open it in a browser, it's xml formatted with the current
IP address between the <ipaddresstags.
So the php code is executed.
My RSS reader (SharpReader, Feedreader) doesn't display the
IP address (php code). It displays only the description (tag).
It seems that it can't handle the <ipaddresstag.
No, and you shouldn't expect it to. This is not an element defined in
any RSS specification I know of...

Cheers,
NC

Sep 23 '06 #10
No, and you shouldn't expect it to. This is not an element defined in
any RSS specification I know of...
It was an example from Daniel (Cu************@gmail.com ) in his reply.
Now I added a <categorytag for the 'discription' and placed the php-code
between the <descriptiontag.
Now everything works fine :-)

Thanks anyway !!

Robertico
Sep 23 '06 #11
haha, very good!

Robertico wrote:
No, and you shouldn't expect it to. This is not an element defined in
any RSS specification I know of...

It was an example from Daniel (Cu************@gmail.com ) in his reply.
Now I added a <categorytag for the 'discription' and placed the php-code
between the <descriptiontag.
Now everything works fine :-)

Thanks anyway !!

Robertico
Sep 30 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.