Jump to content

ajax retrive text from remote div


dzhax

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...