Home > php教程 > php手册 > php提取字符串中网站url地址的方法,字符串url

php提取字符串中网站url地址的方法,字符串url

WBOY
Release: 2016-06-13 09:19:35
Original
1256 people have browsed it

php提取字符串中网站url地址的方法,字符串url

本文实例讲述了php提取字符串中网站url地址的方法。分享给大家供大家参考。具体分析如下:

今天写一个问答系统上线之后发现有很多人发链接了,由于业务部门要我们过滤掉网站地址了,下面我给大家分享一个提取字符串url地址函数,代码如下:

复制代码 代码如下:

$postInfo['answer2'] ='可以的,商业贷款可摊还36%,公积金贷款可摊还16%|||可以先把账户里的余额提取出来用作首付,然后每个月贷款商业贷款可摊还36%,公积金贷款可摊还16%|||可以的,现在甲类公积金是摊还比例http://www.bkjia.com 是工资基数的34%|||啊啊啊啊啊啊啊啊是的|||可以摊还,甲类34%
';
 
preg_match_all("/http:[\/]{2}[a-z]+[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*[\/]*[A-Za-z\d]*[\/]*[A-Za-z\d]*/",$postInfo['answer2'],$array2);
 
print_r($array2);
 
if(!emptyempty($array2[0]))
{
 foreach ($array2[0] as $k=>$v){
  $postInfo['answer2'] = str_replace($array2[0][$k],'',$postInfo['answer2'] );
 }
}


 
运行结果为:

复制代码 代码如下:

(
    [0] => Array
        (
            [0] => http://www.bkjia.com
        )
)

希望本文所述对大家的PHP程序设计有所帮助。

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