Link to home
Create AccountLog in
MOSTAGHASSIFlag for United States of America

asked on

Extract xml file from php file for RSS.


I have  create rss.php file with php+mysql for RSS feed ,now i want that extract the rss.xml file from rss.php for publish on search engines ,please help me that how can i do this?
My codes are as below.
header('Content-Type: application/rss+xml');
ini_set('display_errors', 1); 
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">  
<title>My Website Name</title>  
<description>A test of the feed</description>  
<link>The URL to the website</link> 


//connect to the database and check the connection
$mysqli = new mysqli("$dbhostmag", "$dbusermag", "$dbpassmag", "magazine");
if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
//run the query and check it's all OK.
$query = "
	SELECT tbarticles.articleid, tbarticles.title, tbarticles.state, substr(tbarticles.articlebody,1,200) as description1, tbphotos.photofilename, tbarticles.deletitem, tbarticlecategories.catid, tbcategories.parentid, tbarticles.mediastate	 
	FROM tbarticles 
	INNER JOIN tbphotos ON tbphotos.articleid = tbarticles.articleid 
	INNER JOIN tbarticlecategories ON tbarticlecategories.articleid = tbarticles.articleid
	INNER JOIN tbcategories ON tbcategories.catid = tbarticlecategories.catid
	WHERE tbarticles.deletitem='1'
	ORDER BY tbarticles.articleid DESC
	LIMIT 60";

$result = $mysqli->query($query);
if (!$result) die("Error");

//loop through the results and output them
while ($article = $result->fetch_array()): 

$parentid = $article["parentid"];

switch ($parentid) {
	case "48":
	case "49":
	case "99":
	case "107":
	case "108":

	case "1":
	case "2":
	case "3":
		case "53":
   case "54":
   case "56":
   case "59":
   case "63":
   case "65":
   case "67":
   case "68":
   case "69":
   case "70":
	case "132":


		<title ><?php echo $article["title"]; ?></title>
		<link ><?php printf("http://localhost/website/%s/details.php?articleid=%s&parentid=%s&catid=%s</link>", $folder, $article["articleid"], $article["parentid"], $article["catid"])  ?></link>
		<?php echo '<br></br>';?>
		<description><?php echo $article["description1"] ?></description>
		<?php echo '<br></br>';?>
<?php endwhile; ?>


Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account


Hi ~Ray

I have tested it (my codes),and it seems that is ok,but please let me know that  you have deleted the first line:
header('Content-Type: application/rss+xml');

and at the end the  ob_get_clean() is ok? i didn't find it in php manual .

And where must put the xml file (my_rss.xml) ?

Yes, the header() call is not needed if writing the file to disk.

Man page:

And you can put the file anywhere on your server that makes sense for your application.
Ok, but i have a bit confused,i want that i save xml file on my pc local,i executed the codes and in source code i see that xml part is missing and it show that the function could capture xml but ,how access to my_rss.xml ?

I have a warning :

file_put_contents(my_rss.xml): failed to open stream: Permission denied in C:\inetpub\wwwroot\website\General pages\rss1.php on line 276
I don't think I can help with your file permissions from here, sorry.  How do you write other files from your PHP scripts?
I have solved that problem, and now have  access to my_rss.xml,but it is not contain the xml
while when i run .php file it is ok and the xml structure is there.
Please post a link to the PHP script and post the current source code here in the code snippet, thanks.
I try that remove some small error and after i will send.
Sorry, i thought i selected A ,if it is possible i can change it.

You can ask a moderator to change it -- use the request attention button up near the original question.  And if you still have questions or need help with this, please post back and I'll be glad to work through it.  Best, ~Ray
I use that yellow button ,but there is not box that i post my request,please send me its url.
I can't even find the Request Attention button any more on my view of the page.  Another mystery in the "improved" EE design that was rolled out the last time.
Ok, whenever the problem removed please let me know that i correct it via a request to moderator .
10-4, thanks.
Hi ~Ray

Please let me know that is it possible that you reopen the question so i correct the grade.

I have been informed by the moderators that the little yellow triangle is the "Request Attention" button.  EE moves it around (for what purpose, I cannot possibly know) and today it seems to be located at the left of the original question title.  You might try that.  If it doesn't work, don't waste time worrying about it.  Thanks for trying, ~Ray