PHP Simple DOM Parser
Posted
by Junior Coder
on Stack Overflow
See other posts from Stack Overflow
or by Junior Coder
Published on 2010-05-16T05:07:11Z
Indexed on
2010/05/16
5:10 UTC
Read the original article
Hit count: 463
Hi guys I'm using this wonderful class here to do a bit of code embed filtering: http://simplehtmldom.sourceforge.net/. It extends the PHP DOM document class.
Pretty much what I am doing is parsing a string through this class that contains embed code, i grab the unique bits of information eg id, width, height send through a handler function which inserts the id, width, height etc into my predefined "safe" template and reinsert my safe template in the place of the embed code the user has put in. May seem a backward way of doing it but it's the way it has to be done :)
All of that works fine. Problem is when there is more than just embed code contained in the string, as I can't just replace the embed code i can only replace the entire string which wipes the rest of the tags etc string. For example if there were a p tag that would be wiped.
So my question is how using this class can i just replace the certain part of the string? Spent the last few days trying to work this out and need some more input. It appears the class can do this so i'm stumped.
Here's a basic version of what i have so far :)
// load the class
$html = new simple_html_dom();
// load the entire string containing everything user entered here
$return = $html->load($string);
// check for embed tags
if($html->find('embed') == true
{
foreach($html->find('embed') as $element)
{
// send it off to the function which returns a new safe embed code
$element = create_new_embed($parameters);
// this is where i somehow i need to save the changes and send it back to $return
}
}
Any input would be gratefully appreciated. If i have explained my problem well enough please let me know :)
© Stack Overflow or respective owner