【发布时间】:2014-07-22 04:16:05
【问题描述】:
我在这里阅读了一个不同的问题,解决了同样的问题,但我似乎无法弄清楚这里发生了什么。我正在尝试用 str_replace 替换我的代码中的撇号,但它不起作用。我有一个字符串要测试:
$clue_question = "If you’re rowin’ the Rhone from start to finish, you begin in this mountain range";
然后一些字符串替换及其结果:
$new_string = str_replace("I", "a", $clue_question)."<br />";
//af you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$another_new_string = str_replace("'", "VB", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$yet_another_new_string = str_replace("'", "VB", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$sdf_another_new_string = str_replace("`", "VB", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$sdf_another_new_string_sdf = str_replace("ï", "VB", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$yet_another = str_replace("’", "sdgd", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
$yet_another = str_replace("\’", "sdgd", $clue_question)."<br />";
//If you’re rowin’ the Rhone from start to finish, you begin in this mountain range
我试过 ASCII 等价物,我试过转义它们,我试过正常。我不知道为什么我的字符串中没有替换单撇号(或者可能是单引号)。我的语法很好,因为第一个 str_replace() 函数工作正常。我已经用谷歌搜索了,我唯一能想到的是这是我在这里检查另一个问题后的 PHP 版本。我运行了 phpinfo() 并且我的版本为 5.2.17,所以我假设这不是问题。
有什么想法吗?谢谢。
编辑
抱歉,我最初有一个类型,并且初始变量为 $question 而不是 $clue_question。此情况并非如此。我能够在屏幕上打印出字符串并正确设置,只是没有格式化。感谢您迄今为止在这个问题上的活动!
【问题讨论】:
-
只是为了确保,因为在最初的例子中是
$question,然后在你处理它的$clue_question时,它们的内容是否相同?
标签: php str-replace