twittoris Posted September 4, 2010 Share Posted September 4, 2010 I have a DOMDocument which I inspect an HTML page for links (href) That part works however I am not sure how to use preg_match if I only want to display a link in this layout: <tr> <td headers="c1"><a title="Link to entity information." tabindex="1" href="CORPSEARCH.ENTITY_INFORMATION?p_nameid=3236937&p_corpid=3227476&p_entity_name=%41%72%77%65%6E%20%45%71%75%69%74%69%65%73&p_name_type=%41&p_search_type=%42%45%47%49%4E%53&p_srch_results_page=0">ABC LLC</a></td> </tr> I hope someone is really good at preg_match to help me. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/ Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 $patern ='/href="([^"]*)"/'; preg_match_all($patern, $text, $out); print_r($out[1]); Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107246 Share on other sites More sharing options...
twittoris Posted September 4, 2010 Author Share Posted September 4, 2010 I dont think that worked. can you explain it to me? Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107251 Share on other sites More sharing options...
twittoris Posted September 4, 2010 Author Share Posted September 4, 2010 Can you just make DOM pull out url's with CORPSEARCH in it? Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107252 Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 href=" - literaly ( - start groupin [^"]* - any caracter diferant that " zero or more time ) - end gruping " - end caracter Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107254 Share on other sites More sharing options...
twittoris Posted September 4, 2010 Author Share Posted September 4, 2010 I am fairly new at this so I have inserted my code. this is making it say Array over and over again in my database. // parse the html into a DOMDocument $dom = new DOMDocument(); @$dom->loadHTML($html); // grab all the on the page $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//a"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $patern ='/href="([^"]*)"/'; preg_match_all($patern, $text, $out); print_r($out[300]); $sql="INSERT INTO links(cid, nlink)VALUES('$out()','$out')"; $result=mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107257 Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 i see in another your post thet you want href wich start with 'CORPSEARCH.ENTITY_INFORMATION?' in that case use $patern ='/href="(CORPSEARCH\.ENTITY_INFORMATION\?[^"]*)"/'; preg_match_all($patern, $text, $html); $url =$out[1][0]; $sql="INSERT INTO links(cid, nlink)VALUES('','$url')"; Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107260 Share on other sites More sharing options...
wildteen88 Posted September 4, 2010 Share Posted September 4, 2010 Umm, Why another thread? You have already asked this question here http://www.phpfreaks.com/forums/index.php/topic,309147.0.html Quote Link to comment https://forums.phpfreaks.com/topic/212532-preg_match-help/#findComment-1107264 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.