Home >Backend Development >PHP Tutorial >PHP regular expression to extract image address hyperlink title implementation code_PHP tutorial
The article introduces the use of PHP regular expressions to extract image addresses, hyperlinks, titles, and implementation codes. Friends in need can refer to it.
Regular expression to extract id from URL
代码如下 | 复制代码 |
preg_match('/http://t.sina.com.cn/(d+)/fans//',$html,$result); 正则表达式提取网址中的id echo $result[1]; |
PHP regular expression code to extract image address.
代码如下 | 复制代码 |
$str=''; $pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg]))['|"].*?[/]?>/"; preg_match_all($pattern,$str,$match); print_r($match); |
PHP regular expression to extract hyperlinks and their titles
The code is as follows
|
Copy code | |||||
Using regular expressions is the simplest. I’d like to think of other methods. . .
http://www.bkjia.com/PHPjc/631607.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631607.htmlTechArticleThe article introduces the implementation code of using php regular expressions to extract image address hyperlink titles. Friends in need can refer to it. . The regular expression to extract the id in the URL code is as follows Copy code...