APPENDING to xml file using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Calipoop
Forum Newbie
Posts: 24
Joined: Fri Sep 17, 2004 6:06 pm
Location: Los Angeles, CA

Resource id #3"1.0"?>

Post by Calipoop »

Oh No! This doestn't seem to be writing to the file... after I open the modified xml file, the only change is at the beginning of the xml file where instead of saying
<?xml version="1.0"?>
it says
Resource id #3"1.0"?>
What is that?


here's the php I'm using:

Code: Select all

<?php
$raw_xml = file_get_contents('php://input');

//ignore the document type
$raw_xml = preg_replace("/\<\?xml.*?\>/", '', $raw_xml);
$raw_xml = trim($raw_xml);

//open the file for reading and writing
$fp = fopen("Stories.xml", "r+b");

//add new story
$storiesFileNew = preg_replace("</stories>", "$raw_xml </stories>", $fp);

//write to file
fwrite($fp, $storiesFileNew);
fclose($fp);

//send to flash
print $raw_xml;
?>
Any idea what I'm screwing up? Also, if I want to read, write and also keep it binary functional, would I use

Code: Select all

<?php
$fp = fopen("Stories.xml", "r+b");
?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you are nowhere reading.
Post Reply