字符串 PHP 中的剥离标签(也在源代码中!

本文关键字:源代码 标签 PHP 剥离 字符串 | 更新日期: 2023-09-27 18:31:23

我刚刚删除了我的问题,因为我认为它是以下内容的副本:条形标签和介于两者之间的所有内容但是:那里给出的选项只是"隐藏"标签。检查源代码时,标签都还在。

当我查看代码源代码时,我的备忘录会在 .

<td>Memo:</td><td><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8" /><title>
        </title>
        <style type="text/css">
            .cs95E872D0{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt}
            .csEE99116A{color:#08343E;background-color:transparent;font-family:Arial; font-size:12pt; font-weight:normal; font-style:normal; }
        </style>
    </head>
    <body>
        <span><p class="cs95E872D0"><span class="csEE99116A">dubbel test hoi</span></p></span></body>
</html>
</td>

现在,我唯一想看到的是dubbel test hoi我确实看到的<span><p class="cs95E872D0"><span class="csEE99116A">dubbel test hoi</span>,但在源中它看起来仍然很糟糕。

我尝试了所有类型的功能,其中大多数都剥离了一些东西,但保留了 CSS IDS,有些只是"隐藏"它,所以它在源代码中仍然可用。

有什么建议吗?

我的输入文本是来自PHP表单的纯文本,然后它进入数据库并发送到C#应用程序,该应用程序将文本转换为RTF。在我的"仪表板"的这个页面中,我请求文本,该文本现在采用 RTF,并将 RTF 转换为 HTML 文本。

这是我将文本转换为HTML文本的代码:

private string ConvertToHtml(string value)
        {
            if (RtfTags.IsRtfContent(value))
            {
                using (RichEditDocumentServer richServer = new RichEditDocumentServer())
                {
                    string htmlText = string.Empty;
                    richServer.RtfText = value;
                    CharacterProperties cp = richServer.Document.BeginUpdateCharacters(richServer.Document.Range);
                    cp.FontName = "Arial";
                    cp.FontSize = 12;
                    cp.ForeColor = System.Drawing.ColorTranslator.FromHtml("#08343e");
                    richServer.Document.EndUpdateCharacters(cp);
                    htmlText = richServer.HtmlText;
                    return htmlText;
                }
            }
            else
            {
                return value;
            }
        } 

字符串 PHP 中的剥离标签(也在源代码中!

我在这里找到了 http://www.php.net/manual/en/function.strip-tags.php#17656 解决方案。只需替换样式代码,然后使用strip_tags:

$htmlstring = preg_replace("'<style[^>]*>.*</style>'siU",'',$htmlstring);
echo strip_tags($htmlstring);