0

Hello all
I have never posted before and bit of a noob
I have a problem i hope someone can help with...
I have a wysiwig editor (nicedit) attached to a page which gets called
and allows the user to edit portions of the page in a modal window.

This changed content then gets serialized, with the ID of the div and posted to the server. I want to be able to update the html of the div in question on the page using PHP. This content is not in a database but on the page itself. What i would like is some direction?

Regex solutions all seem to point to the problem that if the div in question has nested divs the regex will take the first closing tag.

PHP dom parser looks to be the right solution but i have had trouble
getting it to work.

Any advice would be greatly appreciated
Cheers
Davros

3
Contributors
6
Replies
8
Views
8 Years
Discussion Span
Last Post by davrosboy
0

Hi Davros and welcome to DaniWeb :)

So are you trying to change the code that embeds the editor on the fly? If so, according to what criteria? I'm a little confused as to what you want to achieve.

0

Hi darkagn

What i have done is set up a web page editor which has a on hover fade effect for editable divs, when you click on the editable div the wysiwig editor pops-up in a modal window, once you have finished editing the region it has a save button which serializes the editor content and then POST's it with the editable regions ID using ajax. On the server side this data is unserialized into the div id and the wysiwig content.
I need to replace the original div with the contents of the posted data.
So i essentially need to open the page, find the old div using the id that i posted and then replace that div, then save the page.
My real problem is how to find a div in a page by its id, and then replace the div with something else.

Cheers
Davros
copy the new div contents(the posted data) in its place and then

0

PHP dom parser looks to be the right solution but i have had trouble
getting it to work.

Have you tried the DOMDocument::getElementById() function? Can you post your coding attempt with the DOM parser please?

0

Thanks for helping

<?php
$string = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>   
<div id="fullcontent">
 <div class="leftone"><p>some left text</p></div>
 <div class="rightone"><p>some right text</p></div>
	</div>
</body>
</html> ';
$postedid = "fullcontent";
$posteddata = '<div id="fullcontent">
 <div class="leftone"><p>some new left text</p></div>
 <div class="rightone><p>some new right text</p></div>
	</div>';
$html = new DOMDocument;
$html->loadHTML($string);
$elements = $html->getElementById($postedid);
$newelement = $html->createTextNode($posteddata);
$elements->parentNode->replaceChild($newelement, $elements);
echo $html->saveHTMLFile("test.html");
$testget = file_get_contents("test.html");
echo $testget;
?>

This is my attempt so far, i am learning as i go,
this outputs the posted data and seems to replace the whole string.


Cheers
Davros

0
document.getElementById('thedivid').innerHTML = yourajaxoutput;

Place this in a js file.

I would personally save the content to a db field and call it via php (or ajax if you don't want page refresh), but there's more than one way to cook an egg.

0

Thanks ardav
This method has crossed my mind, my thinking was if i had a large number of people accessing a large number of pages that were all generated by mysql data and php that would cause alot of server work, whereas page edits
would be far less frequent, and the mostly flat files would download faster? dunno, I think i am close

Cheers
Davros

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.