Page 1 of 1

writing to an XML with PHP

Posted: Wed Sep 11, 2002 8:56 am
by kendall
hi,

I am new to php and although php has xml support i am not using it cause i am not too familiar with it

i created a simple php script that writes information from a form to an xml file using fwrite()

the outputstring is as follows

---file--
<?xml version="1.0" encoding="iso-8859-1"?>
<guestbook>
</guestbook>
--endfile--

---code----

$data = "<guest date=\"date('jS F Y')\">\n"."<name>\n".$_POST[Name]."</name>\n"."<email>\n".$_POST[Email]."</email>\n"."<comments>\n".$_POST[Comments]."</comments>\n"."</guest>\n"."</guestbook>";

$file = str_replace("</guestbook>",$data,$file);

---end ----
then i write the file

however in tryin to view the xml file i get nuthing and viewing the source code reveals html content

can i just write to the xml file withou any php/cml functions?

Posted: Thu Sep 12, 2002 4:41 am
by volka
not using a xml-api you have to take care writing valid xml-code on your own.
How do you view the file?

guest book using PHP and XMl

Posted: Thu Sep 12, 2002 8:04 am
by kendall
well i dont know yet i was thinking of having php do dat but my first step was getting it to write to the xml file

the code shown was something i thought i cud have done. I mean to say i am using the theory as if it were a text file

is this possible to just fread() the xml file to a variable and then just spit it back out to the browser once i do a formatting code in php

thus waht i am saying is this
let say i have the xmlf file <guestbook>this is text</guestbook> php freads it
and i use a replace code to replace xml tags with html tags and wallah spit it back out to the browser like normal

cant that work without the xml api mumbo jumbo?

Kendall

Posted: Thu Sep 12, 2002 1:53 pm
by hob_goblin
the whole point of using XML with PHP is to use the xml functions...

what you're trying to do is basically drive a flintstones car on the highway, it's not worth it.