doujing2497 2011-11-26 00:33
浏览 47
已采纳

如何搜索html标签并将其删除

I have made a description system, but all which doesn't work is my "search and delete unwanted tags"-system... Here's the code:

$mystring = $description;
$findme   = '<';
$pos = strpos($mystring, $findme);
echo $pos;

if ($pos == false) {
    $user = mysql_query("SELECT * FROM members WHERE username='$myusername' AND password='$mypassword'");
    while($row=mysql_fetch_array($user)) {
        mysql_query("UPDATE members SET description = '$description' WHERE username = '$myusername' AND password = '$mypassword'");
        echo "<tr><td colspan='2'><span style='color:#0076c9;'>Your description has successfully been changed! Go back to your page to see the changes!</span></td></tr>";
    }
} else {
    echo "<tr><td colspan='2'><span style='color:#F00;'>Invalid input! Make sure that no other code than <br /> can be typed in!</span></td></tr>";
}

Is there any possible way of doing this? I have seen it on YouTube, but are too good! Anyone who knows how to do it?

Oh and I also noticed that my function only shows the position of the first tag... Not all tags and it can't see the difference between a <br /> (which is allowed) and an <img> (not allowed).

  • 写回答

3条回答 默认 最新

  • douying7289 2011-11-26 00:43
    关注

    If you want to remove HTML tags and only allow some of them you can use strip_tags function like this

    strip_tags($text, '<br><a>');
    

    This will return the text you entered $text with no tags except <br> & <a> tags You can read more about strip_tags Here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog