Avatar of JohnLourdu
Flag 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.
PHPJavaScriptResponsive Web

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.