[英]PHP to XML - Replace/Trim Special Character
How do I replace ”
into "
in my php code? 如何在我的PHP代码中将”
替换为"
?
Current XML output (Partial) 当前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>
As you can see there is ”
wrapping clear:both;
正如您所看到的,有”
换行clear:both;
style. 样式。 All I want is replace it to "
. 我只想将其替换为"
。
My PHP Code (not working) 我的PHP代码(无法正常工作)
<content type="html"><![CDATA[<?php echo str_replace("\”","",$row["content"]); ?>]]></content>
PS: The ”
already inside database. PS:数据库中已经有”
。
Update: 更新:
If you test on your server with 如果您使用以下命令在服务器上进行测试
<?php
$data = "<a style=”clear:both;”></a>";
echo str_replace('”','"',$data);
?>
Output : "clear:both;"
It will never work. 它永远都行不通。
But if you try with 但是如果你尝试
<?php
$data = "”clear:both;”";
echo str_replace('”','"',$data);
?>
Output : nothing
It's working! 工作正常! But I want it work within tag.... 但是我希望它在标签内工作。
I've just tested, and the following is working fine for me: 我刚刚测试过,以下对我来说很好用:
<?php echo str_replace ( '”','"', $row["content"] ); ?>
I'm replacing ” with ". 我将“替换为”。
Edit: Replace the quotes in your source or if not possible, before you insert it to your database. 编辑:在您将其插入数据库之前,请替换源中的引号,或者如果不可能的话。
<?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"] );
In you're case. str_replace ( "”","\\"", $row["content"] );
在这种情况下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.