【问题标题】:Handle string in PHP, ignoring HTML tags在 PHP 中处理字符串,忽略 HTML 标签
【发布时间】:2012-11-28 16:44:35
【问题描述】:

我正在尝试处理可能输入的字符串

'something <p>hi</p> <br />'

输入字符串可以包含任何 HTML 标记,也可以不包含任何 HTML 标记。我想处理这个字符串而不格式化它。

基本上我现在正在拆分它,用 & 分隔符,我需要生成的输出数组仍然包含输入

等等……
$ajaxinput = "function=submit&content=this is some page stuff <p>hi</p>";

        echo 'Input : ' . $ajaxinput . '<br /><br /><br />';

        $output = explode("&", $ajaxinput);
        echo 'Split : ' . $output[0] . '<br /><br />';
        echo 'Split : ' . $output[1];

输出是:

Input : function=submit&content=this is some page stuff
hi




Split : function=submit

Split : content=this is some page stuff
hi

我想要:

Input : function=submit&content=this is some page stuff <p>hi</p>




Split : function=submit

Split : content=this is some page stuff <p>hi</p>

【问题讨论】:

  • 你想达到什么目的?问题是什么?
  • 我已经在 :) 中编辑过了

标签: php html string tags


【解决方案1】:

由于您不删除 HTML 标记,因此它们必须存在。但由于它们是 HTML 标签,除非您使用“查看源代码”菜单项,否则您无法在浏览器中看到它们。

【讨论】:

    【解决方案2】:

    如果您想显示这些标签,请查看htmlentities(这是我在阅读您的问题后的假设):

    echo htmlentities($str, ENT_QUOTES, "UTF-8");
    

    htmlentities 会将所有适用的字符转换为 HTML 实体。

    【讨论】:

      猜你喜欢
      • 2015-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多