首页 > php代码 > php 正则得到url的地址代码

php 正则得到url的地址代码

<?php
$str = '<a href="http://www.phprm.com" target="_blank" name="doc3_p">
<img src="" onload="setImgSize(this,170,170);"></a>';
preg_match_all ('|^<a href="(.*)".*|U',$str,$out, PREG_PATTERN_ORDER);
print_r($out);
//方法二
preg_match_all('/href=[\'"]+(.*)[\'"]+/',$str,$matches);
var_dump($matches[1]);
//方法三
//(?<=<as*)href=[^ '">]+
//方法四
preg_match("/<as*href=\"(.*?)\"[^>]*>.*?</a>/is", $str, $aMatch);
print_r($aMatch[1]);
//方法五
preg_match_all('/href=(\'|"|s)*([^\'">s]+)/i',$str,$match);
print_r($match);
preg_match_all('/src=(\'|"|s)*([^\'">s]+)/i',$str,$match);
print_r($match);
/*
上面这正则得到url的地址都是用了php正则表达试来实现的,只是方法有一点不同了。
*/


本文地址:http://www.phprm.com/code/33363.html

转载随意,但请附上文章地址:-)

标签:none

发表留言