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

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

WBOY
Release: 2016-06-21 08:57:27
Original
2352 people have browsed it

用正则表达式求出内容里面的以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>?>



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template