如何在php twitter自动转发中打印时转义单引号


How to escape single quotes while printing in php twitter autotweet?

我有将文本自动转发到twitter帐户的功能。一切都很好,但当文本包含任何单引号时,它会在推特上发布如下。。

示例:实际文本和预期结果:Maneka的"Beti Bachao"驱动器上线

推特上显示的文本:Maneka�s�贝蒂·巴超�驱动器启用

请让我知道如何在php中转义这些单引号。

谨致问候,基兰。

试着像这样使用htmlenties():

<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>