writing to an XML with PHP

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

writing to an XML with PHP

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

guest book using PHP and XMl

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
Post Reply