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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助