Home > Backend Development > PHP Tutorial > Use PHP to implement small programs that dynamically generate XML files and extract data from XML files and convert them into HTML. . . No need for DOM. . _PHP Tutorial

Use PHP to implement small programs that dynamically generate XML files and extract data from XML files and convert them into HTML. . . No need for DOM. . _PHP Tutorial

WBOY
Release: 2016-07-13 16:58:02
Original
778 people have browsed it

This stuff has been messing with me all day. . . But in the end, I found that I couldn't achieve the effect I imagined. . . What a shame. . . It seems that PHP needs to be strengthened for XML. . . If anyone has research on this. Welcome to write to discuss. . .
First create the table:
CREATE TABLE books (
bookid int(4) NOT NULL auto_increment,
bookname varchar(100) NOT NULL,
bookauth varchar(50) NOT NULL,
bookpublisher varchar(50) NOT NULL,
bookpubdate datetime NOT NULL,
bookurl varchar(50) NOT NULL,
KEY bookid (bookid),
);
Then. . . This section is the source code for converting data from MYSQL into XML:
$connect_id=mysql_connect("localhost","root","");
mysql_select_db("bbs", $connect_id);
$query="select * from books order by bookid";
$rs=mysql_query($query,$connect_id);
$numfields=mysql_num_fields($rs);
$xmlfile=" ";
$xmlfile.=" ";
while($row=mysql_fetch_array($rs)){
for($i=0;$i<$numfields;$i++){
$fieldname=mysql_field_name($rs,$i );
           $xmlfile.="<" . $fieldname . ">" . $row[$i] . " ";
 }
}
mysql_free_result($rs);
mysql_close($connect_id);
$xmlfile.="
";
$fp=fopen("xmldoc/xmldoc.xml","w");
if(fwrite($fp,$xmlfile)){
echo "Write file successfully!";
}
else{
echo "Failed to write file!";
}
?>
This is the source code that takes data from XML and converts it into HTML. .
class xml{
var $parser;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631451.htmlTechArticleThis stuff bothered me all day. . . But in the end, I found that I couldn't achieve the effect I imagined. . . What a shame. . . It seems that PHP needs to be strengthened for XML. . . If anyone...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template