English 中文(简体)
利用PHP生成XML文档
原标题:Using PHP to generate an XML file
  • 时间:2012-04-11 20:51:53
  •  标签:
  • php
  • mysql
  • xml

目前,我有一本PHP书,在生产XML文档时(无论作为饲料)。 php没有饲料。 我被告知,在我的接触中,我还要补充这一点。

AddType application/x-httpd-php .xml

然而,出于某种原因,那就没有工作。

我完全喜欢用文字做些什么——如果是产生一个含有其内容产出的饲料——xml文档,而不是仅仅将内容投放到文件箱上。

我的守则是:

<?PHP
 include("../config.php");
 #// Timetable Clearup Variabls
$yesterday = strtotime( yesterday );
$yesterdow = date( l ,$yesterday);
$order = "SELECT * FROM timetable WHERE day =  $yesterdow  ORDER BY time";
$result = mysql_query($order);
$yesterdayd = date( F jS, Y , time()-86400);

    //SET XML HEADER
    header( Content-type: text/xml );

    //CONSTRUCT RSS FEED HEADERS
    $output =  <rss version="2.0"> ;
    $output .=  <channel> ;
    $output .= "<title>Timetable - {$yesterdayd} </title>";
    $output .=  <description>Timetable.</description> ;
    $output .=  <link>http://site.com/</link> ;
 ###   $output .=  <copyright>Your copyright details</copyright> ;
 while ($row = mysql_fetch_array($result)) {
    //BODY OF RSS FEED
   $output .=  <item> ;
     $output .= "<description><td>" . htmlspecialchars($row[ username ]) . "</td><td>" . htmlspecialchars($row[ time ]) . "</td></description>";
   $output .=  </item>  ;
 }
    //CLOSE RSS FEED
   $output .=  </channel> ;
   $output .=  </rss> ;

    //SEND COMPLETE RSS FEED TO BROWSER
    echo($output);

?>
问题回答

I would suggest not adding .xml in .htaccess to be processed using PHP compiler. Rather use mod_rewrite to redirect requests to .xml files to php script.

例如:

RewriteEngine On
RewriteRule ^(.*).xml$ /rss_feed.php [L,QSA]




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签