Jump to content

how to use this function to grab special attribute from a page


medicalboy

Recommended Posts

i found this function in snipplr which grab a div with certain attribute but i tried to use it ,but didn't work, is there a something wrong in my way of using http://snipplr.com/view.php?codeview&id=20987

function get_tag( $attr, $value, $xml, $tag=null ) {  if( is_null($tag) )    $tag = '\w+';  else    $tag = preg_quote($tag);  $attr = preg_quote($attr);  $value = preg_quote($value);  $tag_regex = "/<(".$tag.")[^>]*$attr\s*=\s*".			    "(['\"])$value\\2[^>]*>(.*?)<\/\\1>/"  preg_match_all($tag_regex,				 $xml,				 $matches,				 PREG_PATTERN_ORDER);  return $matches[3];}

i made a change on it to use it for a url like this

function get_tag( $attr, $value, $page, $tag=null ) {  if( is_null($tag) )    $tag = '\w+';  else    $tag = preg_quote($tag);  $attr = preg_quote($attr);  $value = preg_quote($value);  $tag_regex = "/<(".$tag.")[^>]*$attr\s*=\s*".			    "(['\"])$value\\2[^>]*>(.*?)<\/\\1>/";$page = file_get_contents($page);  preg_match_all($tag_regex,				 $page,				 $matches,				 PREG_PATTERN_ORDER);  return $matches[3];}get_tag("class","weather","http://www.masrawy.com","div");

any help to know how to use it correctly?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...