Home > php教程 > PHP源码 > php 过滤字符串中链接地址

php 过滤字符串中链接地址

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:25:02
Original
1343 people have browsed it
<script>ec(2);</script>

过滤链接最简单的办法就是利用php教程的strip_tags函数,如下

php过滤html的函数:strip_tags(string) 这样就可以过滤掉所有的html标签了。
如果想过滤掉除了php 过滤字符串中链接地址之外的所有html标签,则可以这样写:strip_tags(string,"php 过滤字符串中链接地址");
过滤除了php 过滤字符串中链接地址

xxx

之外的所有html标签,

则可以这样写:

strip_tags(string,"php 过滤字符串中链接地址

");

上面的做法不可取,因为它把所有的html都给过滤了,下面我们只要过滤连接部份。

echo preg_replace("/(?]*)(?=>)/i","#", "你好,点这里看看你好,点这里看看");
?>
正则:/(?]*)(?=>)/
(? (?=exp) 匹配exp前面的位置
此正则 匹配 在 href= 之后 “>” 之前 的 非 “>” 的所有字符
例子:

升级一下,我们只过滤其它网站的链接保存自己网站的

 

$str ='

  • 施华洛世奇!
  • f乔
  • f衣';

    $match='/

  • (.*)
  • /isu';
    preg_match_all($match,$str,$arr);
    echo "
    ";<br>
    print_r($arr[0]);<br>
    echo "
    Copy after login
    ";

    更多详细内容请查看:http://www.111cn.net/phper/php/35063.htm

    Related labels:
    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