I have previosly saved a string to a .txt like this:
$text = "<div class='highlight'><div><p>".$date.".</p> <h1> ".$heading."</h1>".$textbox."</div></div>";
I now want to extract $date, $heading and $textbox from the txtfile back to variables, for the purpose of editing and I have no clue how to do this.
Can anyone help me?
You need to use a DOM parser to parse the HTML.
http://simplehtmldom.sourceforge.net/
Code posted from the above site.
$html = file_get_html('http://www.google.com/'); // Find all images foreach($html->find('img') as $element) echo $element->src . ''; // Find all links foreach($html->find('a') as $element) echo $element->href . '
';
OR PHP’s DOM
//get all H1
$items = $DOM->getElementsByTagName(‘h1’);
//display all H1 text
for ($i = 0; $i < $items->length; $i++)
echo $items->item($i)->nodeValue . “
“;