Trying to replace contents of a Div, with no luck
Posted
by bluedaniel
on Stack Overflow
See other posts from Stack Overflow
or by bluedaniel
Published on 2010-05-24T16:58:42Z
Indexed on
2010/05/24
17:21 UTC
Read the original article
Hit count: 285
Ive tried to use the Dom model with no bloody luck, getElementByID just doesnt work for me.
I loathe to resort to a regex but not sure what else to do.
The idea is to replace a <div id="content_div"> all sorts </div>
with a new <div id="content_div"> NEW ALL SORTS HERE </div>
and keep anything that was before or after it in the string.
The string is a partial HTML string and more specifically out of the wordpress Posts DB.
Any ideas?
UPDATE: I tagged this question PHP but probably should of mentioned Im looking for a PHP solution only.
Update: Code Example
$content = ($wpdb->get_var( "SELECT `post_content` FROM $wpdb->posts WHERE ID = {$article[post_id]}" ));
$doc = new DOMDocument();
$doc->validateOnParse = true;
$doc->loadHTMLFile($content);
$element = $doc->getElementById('div_to_edit');
So Ive tried a whole lot of code and this is what Ive got so far, probably not right but Ive been hacking at it for a little while now.
© Stack Overflow or respective owner