Slip 18 - B) Write a PHP script to generate an XMLin the following format. Add more than 5 books details. Display details of book by selecting the publication of book from user.

 Solution:

HTML file-

<html>
<head>
<title>Create XML</title>
</head>
<form action=slip23.php.php method=get>
Enter Book Title<input type=text name=txtTitle>
Enter Publication<input type=text name=publ>
<input type=submit value="submit">
</form>
</html>

PHP File-

<?php
echo "Links data posted";
$ele=$_GET['txtTitle'];
$att=$_GET['publ'];
$xmltags="<?xml version=1.0?>";
$xmltags=$xmltags."<Bookstore>";
$xmltags=$xmltags."<Books>";
$xmltags=$xmltags."<PHP>";
$xmltags=$xmltags."<title>";
$xmltags=$xmltags.$ele;
$xmltags=$xmltags."</title>";
$xmltags=$xmltags."<publication>";
$xmltags=$xmltags.$att;
$xmltags=$xmltags."</attrib>";
$xmltags=$xmltags."</PHP>";
$xmltags=$xmltags."</Books>";
$xmltags=$xmltags."</Bookstore>";
if($fp=fopen("books.xml","w"))
{
if($wt=fwrite($fp,$xmltags))
{
echo "File created";
}
else
echo "Not write";
}
else
echo "Not opened";
?>

Post a Comment

0 Comments