dzhax Posted October 6, 2010 Share Posted October 6, 2010 I am trying to retrive all the text/html from a div on another page.I know that all the information will be in <div class="guidecontent"></div>i saw this example: preg_match('/\<div id\=[\"]{0,1}ad_content[\"]{0,1}\>(.*?)\<\/div\>/s', $content['content_body'], $matches);$content['content_body'] = $matches[1]; But i'm not sure how to use it.and someone posted on that forum, if there is an inner-div inside the div you are trying to grab it stops at the end of it instead of at the end of the div you want. Link to comment Share on other sites More sharing options...
dzhax Posted October 6, 2010 Author Share Posted October 6, 2010 I found some more code but its not working <? $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://runehq.com/guide.php?type=skill&id=0722"); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($curl, CURLOPT_TIMEOUT, 6); $full = curl_exec($curl); if (preg_match('/<div class=\"guidecontent\">(.*?)<\/div>/', $full, $matches)) { echo $matches[2]; } else { echo 'Nothing found!'; }?> just to make sure im using it right it should find<div class="guidecontent">it keeps returning the Nothing Foundbut its definitly in the source of the page. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 6, 2010 Share Posted October 6, 2010 Those slashes before the quotes are probably screwing it up, those are literal slashes, they're not escaping anything. Link to comment Share on other sites More sharing options...
dzhax Posted October 6, 2010 Author Share Posted October 6, 2010 nope that did not fix it...im new to regular expressions what does this part do? (.*?) basically i need to grab anything and i mean anything between those div tags.anyone good at writing these? Link to comment Share on other sites More sharing options...
jeffman Posted October 6, 2010 Share Posted October 6, 2010 The easier way to do this is to load the other page as a DOMDocument. Then you can search through it using methods like getElementByIdhttp://us2.php.net/manual/en/class.domdocument.phpThe link is in the XML section, but there are HTML methods specifically. Link to comment Share on other sites More sharing options...
dzhax Posted October 6, 2010 Author Share Posted October 6, 2010 The easier way to do this is to load the other page as a DOMDocument. Then you can search through it using methods like getElementByIdhttp://us2.php.net/manual/en/class.domdocument.phpThe link is in the XML section, but there are HTML methods specifically.but the div does not have an id just a class...also not really sure how to use this Link to comment Share on other sites More sharing options...
dzhax Posted October 6, 2010 Author Share Posted October 6, 2010 i got it. <? $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://runehq.com/guide.php?type=skill&id=0722"); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($curl, CURLOPT_TIMEOUT, 6); $full = curl_exec($curl); $lines = explode("<div class=\"guidecontent\">", $full); $lines2 = explode("</div>", $lines[1]); echo $lines2[0];?> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.