using fwrite to write an xml file cause me issues

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

Post Reply
marclar83
Forum Newbie
Posts: 2
Joined: Sun Jun 14, 2009 6:06 pm

using fwrite to write an xml file cause me issues

Post by marclar83 »

I try to write an xml file using the command fopen and fwrite in a php file and flash to send the content to php, but the string that I want to pass to php contain the " ' " symbols when the file is written, the ' is replaced by \'. I can't find a way to generate my file properly

php file look like this:

<?
$receivedFromFlashData = $_POST['inputData'];
$myTextFileHandler = @fopen("myTextFile.xml","w");

$txtfileArray = @file("myTextFile.xml");

if($myTextFileHandler){
print("txtFile is opened\n");
foreach($txtfileArray as $count => $member);
$gotoLastByteOfTxTFile = @fseek($myTextFileHandler,0,SEEK_END);
$count = $count + 1;
$writeInTxtFile = @fwrite($myTextFileHandler,"$receivedFromFlashData");

if($writeInTxtFile){
$writeStatus = "writing to textfile was a succes";
print("&writeStatus=$writeStatus");
};
@fclose($myTextFileHandler);
?>

the result that I want should like this:

<?xml version='1.0' encoding='UTF-8'?>

<Worlds>
<Floor>
<Param param_id='Box_Id'>0</Param>
<Param param_id='Row'>0</Param>
<Param param_id='Col'>0</Param>
<Param param_id='Propriete'>grass</Param>
<Param param_id='flag'>walkable</Param>
</Floor>
<Floor>
<Param param_id='Box_Id'>1</Param>
<Param param_id='Row'>0</Param>
<Param param_id='Col'>1</Param>
<Param param_id='Propriete'>grass</Param>
<Param param_id='flag'>walkable</Param>
</Floor>
</Worlds>

But i got this instead:

<?xml version=\'1.0\' encoding=\'UTF-8\'?>

<Worlds>
<Floor>
<Param param_id=\'Box_Id\'>0</Param>
<Param param_id=\'Row\'>0</Param>
<Param param_id=\'Col\'>0</Param>
<Param param_id=\'Propriete\'>grass</Param>
<Param param_id=\'flag\'>walkable</Param>
</Floor>
<Floor>
<Param param_id=\'Box_Id\'>1</Param>
<Param param_id=\'Row\'>0</Param>
<Param param_id=\'Col\'>1</Param>
<Param param_id=\'Propriete\'>grass</Param>
<Param param_id=\'flag\'>walkable</Param>
</Floor>
</Worlds>

Can someone has an idea?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: using fwrite to write an xml file cause me issues

Post by califdon »

marclar83
Forum Newbie
Posts: 2
Joined: Sun Jun 14, 2009 6:06 pm

Re: using fwrite to write an xml file cause me issues

Post by marclar83 »

Thanks :D :D :D :D :D
Post Reply