Home >Backend Development >PHP Tutorial >PHP regular expression to extract image address hyperlink title implementation code_PHP tutorial

PHP regular expression to extract image address hyperlink title implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:56:211111browse

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';

利用正则表达式是最简单的,其它的办法,偶米去想。。。

$pat = '/(.*?)/i';
preg_match_all($pat, $str, $m);

输出方法:

print_r($m[2]);
print_r($m[4]);

 代码如下 复制代码

$str = '歌曲列表
中文金曲榜

轻音乐
Copy code
$str = ' Song list
Chinese Golden Melody Chart
• Light music';

Using regular expressions is the simplest. I’d like to think of other methods. . .

preg_match_all($pat, $str, $m); Output method: print_r($m[2]); print_r($m[4]);
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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn