Use PHP's regular expression correlation function to extract HTML hyperlink <a href= address in "address" ></a>
<?php
$preg = '/<a. *?href= ' (. *?) ". *?>/is ';
$str = ' <a href= ' link 1 >URLNAME</a> text segment 1<a href= "Link 2" target= "_blank" >URLNAME</a> text segment 2<a target= "_blank" href= "link 3" >URLNAME</A> Text Segment n ';
Preg_match_all ($preg, $str, $match);//Search in $STR matches all $preg join $match
for ($i =0; $i <count ($match [1]), $i + +)//Output hyperlink address one by one
{
echo $match [1][$i]. " <br/> ";
}
?>
Final output:
Link 1<br/> link 2<br/> link 3<br/>
Attached to a
PHP's regular expression extracts the code for the image address.
$str = ' <p style= ' padding:0px; margin-top:0px; margin-bottom:0px; line-height:200%; " ></p><p style= "padding:0px; margin-top:0px; margin-bottom:0px; line-height:200%; " ></p><p style= "padding:0px; margin-top:0px; margin-bottom:0px; line-height:200%; " ></p> ";
$pattern = "/<[img| Img].*?src=[' | "] (.*? (?: [. gif|. JPG])) [' | ']. *? [/]?>/];
Preg_match_all ($pattern, $str, $match);
Print_r ($match);
PHP Regular expression extracts the href address in an HTML hyperlink