Home >Backend Development >PHP Tutorial >PHP regular expression to extract href address in html hyperlink_PHP tutorial
Sometimes we need to filter or extract external links from HTML strings. Below I will introduce a program that uses PHP regular expressions to extract href addresses in HTML hyperlinks for your reference.
Use PHP's regular expression related functions to extract the address in the html hyperlink .
The code is as follows
|
Copy code
|
||||
$preg='//is'; $str ='URLNAMEText 1URLNAMEText 2< a target="_blank" href="Link 3">URLNAME...Text segmentn';
|
Attached is a PHP regular expression code to extract image address.
The code is as follows | Copy code |
$str=' p>'; $pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg]))['|"].*?[ /]?>/"; preg_match_all($pattern,$str,$match); print_r($match); http://www.bkjia.com/PHPjc/631538.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631538.htmlTechArticleSometimes we need to filter or extract external links from html strings. Below I will introduce an extraction using PHP regular expressions. The href address program in html hyperlinks, for your reference. The correct way to use php... |