medicalboy Posted January 14, 2012 Share Posted January 14, 2012 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 More sharing options...
justsomeguy Posted January 17, 2012 Share Posted January 17, 2012 What happens when you run that? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.