把下面一段字符串中的href地址取出来:
<a href="www.1.com" target="_blank">文章标题</a>
<a href="www.2.com" target="_blank">1-1</a> <a href="www.3.com" target="_blank">1-2</a> <a href="www.4.com" target="_blank">1-3</a>
需要得到这样的格式:
<i>www.1.com</i><i>www.2.com</i><i>www.3.com</i><i>www.4.com</i>
谢谢!
------解决方案--------------------
$s=<<<txt
<a href="www.1.com" target="_blank">文章标题</a>
<a href="www.2.com" target="_blank">1-1</a> <a href="www.3.com" target="_blank">1-2</a> <a href="www.4.com" target="_blank">1-3</a>
txt;
preg_match_all('#href="(.+?)"#s',$s,$m);
echo '<li>'.implode('</li><li>',$m[1]).'</li>';
------解决方案--------------------
$str = '<a href="www.1.com" target="_blank">文章标题</a>
<a href="www.2.com" target="_blank">1-1</a> <a href="www.3.com" target="_blank">1-2</a> <a href="www.4.com" target="_blank">1-3</a>';
preg_match_all('<a href="(.*?)">',$str,$val);
foreach($val[1] as $v){
$newstr[]= "<i>$v</i>";
}
print_r(implode("",$newstr));