Home >php教程 >php手册 >php提取字符串中网站url地址程序代码

php提取字符串中网站url地址程序代码

WBOY
WBOYOriginal
2016-05-25 16:45:361219browse

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

例子

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

结果就为

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


教程网址:

欢迎收藏∩_∩但请保留本文链接。

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