Jump to content

Help with Simple XML functionality


halfer2008

Recommended Posts

Hi

 

Im making a simple xml cms to use on my site, doesn't have to be secure or anything but encountered a problem with a / appearing before every ' i use in the text.

 

Anyway my code is as follows: content.php

<?php

// set name of XML file
$file = "content.xml";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// access XML data
echo "Content: " . $xml->text . "\n";

$textContent = $xml->text;

?> 

<form action="save.php" method="post" >
<textarea name="text" value="text"><?=$textContent;?></textarea>
<input type="submit" />		
</form>

 

and save.php

 

<?php


// set name of XML file
$file = "content.xml";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

$text = $_POST['text'];

// modify XML data
$xml->text = $text;

// write new data to file
file_put_contents($file, $xml->asXML());

echo "Content: " . $xml->text . "\n";

?> 

 

Could someone run through with mehow I'd replace the ' and special characters on the way in and then get them back on the way out of the xml?

 

Kind Regards & Thanks in advance

 

Chris

Link to comment
https://forums.phpfreaks.com/topic/106302-help-with-simple-xml-functionality/
Share on other sites

Its to do with the lis etc and nbsp when it goes to load in the xml. Is there a way I can make that stuff xml while also curing the problem i solved by use of the stripslashes?

 

stripslashes is an amturish way of solving problems like these, u are stripping the slashes of XML

i think you need to write the XML to a file because it is ready made with slashes, then u need to read the xml then the slashes will be gone hopefully, or put it in a DB and then read it, people add slashes when they put stuff into databases and fuiles for storage so they know hich characters are not SQL ' is a SQL char so /' put into a db will come out as ', so put it in and take it out of a file or db, xml reader Classes objects usualy write a file and read it from there

Its to do with the lis etc and nbsp when it goes to load in the xml. Is there a way I can make that stuff xml while also curing the problem i solved by use of the stripslashes?

 

stripslashes is an amturish way of solving problems like these, u are stripping the slashes of XML

 

simple methods to solve simple problems. the problem was additional slashes added by magic_quotes in the POST'ed content. to remove extra slashes added by magic_quotes, simply use stripslashes() and you'll get rid of the extra slashes added by magic_quotes while leaving the intended slashes in the content.

hi again

 

@BluSkyIS. yes while the stripslahes() method worked to remove the extra content, I wasn't able to add things like links or ul or ol lists to the xml through the use of tinymce. any ideas on why that wouldn't work, I thought it may be to do with the stripslashes removing additional information i need for them to work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.