Home  >  Article  >  php教程  >  PHP用正则表达式取出http://开头的所有url地址

PHP用正则表达式取出http://开头的所有url地址

WBOY
WBOYOriginal
2016-06-21 08:57:272275browse

用正则表达式求出内容里面的以http://开头的所有url地址

<?php <br/>$str ='<a href="http://localhost">sina.com</a><a href="http://www.olders.net">健康网</a><a href="/aaa.html">sina.com</a>';<br>preg_match_all("/href=\"([^\"]+)/i", $str, $match);<br>$urls = $match[1];<br>$is_url = $_SERVER['SERVER_NAME'];<br>foreach($urls as $value)<br>{<br>    if(strstr($value, $is_url))  continue;<br>    echo $value . "<br>";<br>}<br>?>



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