cdcool1
05-27-2008, 02:59 PM
I've got a variable containing an xhtml page and i'm looking to retrieve the contents of a specific div tag by it's id.
My webserver is running php4.
I've tried two approaches so far. The first was via reg expressions:
preg_match('/<div id="body">(.*?)<\/div>/i', $archivePage, $matches);
But this never found any matches even though there is definately a div tag with id="body". I suspected that it wasn't using the whole page string because of " and ' in the page so i tried addslashes($archivePage) but to no avail.
My second approach is via XML but i've not really moved anywhere here after following this example found here http://www.w3schools.com/PHP/php_xml_dom.asp
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("note.xml");
print $xmlDoc->saveXML();
?>
it returned: Warning: domdocument() expects at least 1 parameter, 0 given
Am I heading in the right direction with either of these ways? I'm really new to php so still finding my feet a bit. I think the reg exps is close but just can't get any content.
Thanks
My webserver is running php4.
I've tried two approaches so far. The first was via reg expressions:
preg_match('/<div id="body">(.*?)<\/div>/i', $archivePage, $matches);
But this never found any matches even though there is definately a div tag with id="body". I suspected that it wasn't using the whole page string because of " and ' in the page so i tried addslashes($archivePage) but to no avail.
My second approach is via XML but i've not really moved anywhere here after following this example found here http://www.w3schools.com/PHP/php_xml_dom.asp
<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("note.xml");
print $xmlDoc->saveXML();
?>
it returned: Warning: domdocument() expects at least 1 parameter, 0 given
Am I heading in the right direction with either of these ways? I'm really new to php so still finding my feet a bit. I think the reg exps is close but just can't get any content.
Thanks