Extracting links from a piece of text in PHP except ignoring image links -


i have piece of text, , want extract links this. links have tags , out there that, in plain format. have images, , don't want links.

how extract links piece of text ignoring image links. , google.com should both extract.

string(441) "<p class="fr-tag">please visit&nbsp;https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg , <a href="https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg" rel="nofollow">link</a>&nbsp;should filtered , this&nbsp;http://d.pr/i/1i2xu&nbsp;<img class="fr-fin fr-tag" alt="image title" src="https://cft-forum.s3-us-west-2.amazonaws.com/uploads%2f1434714755338-screen+shot+2015-06-19+at+12.52.28.png" width="300"></p>" 

i have tried following incomplete:

    $dom = new domdocument();     $dom->loadhtml($html);      $tags = $dom->getelementsbytagname('a');     foreach ($tags $tag) {     $hrefs[] =  $tag->getattribute('href');  

using 1 string test, following works me:

$str =  '<p class="fr-tag">please visit&nbsp;https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg , <a href="https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg" rel="nofollow">link</a>&nbsp;should filtered , this&nbsp;http://d.pr/i/1i2xu&nbsp;<img class="fr-fin fr-tag" alt="image title" src="https://cft-forum.s3-us-west-2.amazonaws.com/uploads%2f1434714755338-screen+shot+2015-06-19+at+12.52.28.png" width="300"></p>';  preg_match('~a href="(.*?)"~', $str, $strarr); 

using a href ="..." in preg_match() statement returns array, $strarr containing 2 values, 2 links google.

array (     [0] => href="https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg"     [1] => https://www.google.co.uk/?gfe_rd=cr&ei=9p2dvaw2bmwo8wfk74hycg ) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -