繁体   English   中英

PHP到XML-替换/修剪特殊字符

[英]PHP to XML - Replace/Trim Special Character

如何在我的PHP代码中将替换为"

当前XML输出(部分)

<content type="html"><![CDATA[<p style="text-align: justify;">Lorem Ipsum is simply dummy text of the printing and typesetting industry.

<p style="text-align: justify;"><br style=”clear:both;”/>Lorem Ipsum is simply dummy text of the printing and typesetting industry.

<p style="text-align: justify;"><br style=”clear:both;”/>Click <a href="http://www.google.com/" target="_blank">here</a> for more information.]]></content>

正如您所看到的,有换行clear:both; 样式。 我只想将其替换为"

我的PHP代码(无法正常工作)

<content type="html"><![CDATA[<?php echo str_replace("\”","",$row["content"]); ?>]]></content>


PS:数据库中已经有
更新:

如果您使用以下命令在服务器上进行测试

    <?php

    $data = "<a style=”clear:both;”></a>";

    echo str_replace('”','"',$data);

    ?>

Output : "clear:both;"

它永远都行不通。

但是如果你尝试

    <?php

    $data = "”clear:both;”";

    echo str_replace('”','"',$data);

    ?>

Output : nothing

工作正常! 但是我希望它在标签内工作。

我刚刚测试过,以下对我来说很好用:

<?php echo str_replace ( '”','"', $row["content"] ); ?>

我将“替换为”。

编辑:在您将其插入数据库之前,请替换源中的引号,或者如果不可能的话。

<?php
    $value = '<p style="text-align: justify;"><br style=”clear:both;”/>Click <a href="http://www.google.com/" target="_blank">here</a> for more information.]]></content>';

    echo $value;
    echo str_replace("”","\"",$value)
?>

在此处输入图片说明

str_replace ( "”","\\"", $row["content"] );在这种情况下

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM