Link to home
Start Free TrialLog in
Avatar of JohnLourdu
JohnLourduFlag for Afghanistan

asked on

How to save DOM content without encoding issues?

I have creating ePub editor in the browser.
After uploading ePub files to server, I have loading the each html file using "iframe".
Loaded iframe content is located in same domain.
I have dynamically loaded iframe content like this:
<iframe scrolling="no" frameborder="0" height="100%" class="readium-flowing-content" style="position: relative; z-index: 0; top: 0px; left: 0px; width: 956px; height: 436px; padding-left: 53px; padding-right: 53px; margin-left: 0px;" src="epub_content/siddhartha3/OPS/s007-Part-001.xhtml" title="Siddhartha - EPUB3"></iframe>

Open in new window

Using HTML5 contenteditable attribute I have saved edited iframe content using ajax and php.
My php code is:
ini_set('display_errors', TRUE);

$content = $_POST['curhtmlbody']; 
$element_id = $_SESSION['curhtmlurl'];

//$content = 'John Lourdu samy'; 
//$element_id = 'epub_content/siddhartha3/OPS/s007-Part-001.xhtml';

if (get_magic_quotes_gpc()) {
function stripslashes_gpc(&$value) {
$value = stripslashes($value);
array_walk_recursive($_GET, 'stripslashes_gpc');
array_walk_recursive($_POST, 'stripslashes_gpc');
array_walk_recursive($_COOKIE, 'stripslashes_gpc');
array_walk_recursive($_REQUEST, 'stripslashes_gpc');


//get the file contents
$file = file_get_contents($element_id);
//use regex to replace what's in between the body tags
$file = preg_replace("/\<body\>(.*)\<\/body\>/Uis",$newcont, $file); 

//open the file in write mode
$myFile = $element_id;
$fh = fopen($myFile, 'w') or die("can't open file");
//write the new contents to the file
fwrite($fh, $file);


Open in new window

My problem is: saved content has encoding issues. It removes all decimal/hex entities to literal characters. How to solve this issue. Please advice.
Avatar of R-Byter
Flag of Serbia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial