替换"’ "与"' "在 PHP 中 [英] Replace " ’ " with " ' " in PHP
问题描述
我正在从数据库中获取一个字符串,它可能类似于 String's Title
但是我需要将 '
替换为 '
这样我就可以将字符串传递给外部 API.我在 str_replace()
中使用了几乎所有我能想到的转义字符串变体,但都无济于事.
I'm grabbing a string from the database that could be something like String’s Title
however I need to replace the ’
with a '
so that I can pass the string to an external API. I've used just about every variation of escaped strings in str_replace()
that I can think of to no avail.
推荐答案
我刚刚测试了这个:
echo str_replace('’', "'", $cardnametitle);
//Outputs: String's Title
我相信您数据库中的条目已经htmlentities
.
I believe that entries in your database have been htmlentities
ed.
注意:我很确定这不是一个好的解决方案,即使它确实解决了您的问题,但我认为应该有更好的方法来做到这一点.
Note: I'm pretty sure this is not a good solution, even though it did solve your problem I think there should be a better way to do it.
这篇关于替换"’ "与"' "在 PHP 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!