【问题标题】:str_replace just returns capsstr_replace 只返回大写
【发布时间】:2010-09-04 02:33:34
【问题描述】:

我在这里遇到了一个小问题..我正在使用 str_replace 替换最常用的单词..由于某种原因,它替换了除大写字母之外的所有字母。

例如..如果我有下面的代码

$str ="Fat string of Text.";    
$commonwords = array('fat','of','random');
$cleantext = str_replace($commonwords,'',$str);

echo $cleantext;

它会回声..F T

任何想法我做错了什么.. 提前谢谢

哦..我试过str_ireplace..但没有

【问题讨论】:

  • 为我工作。 str_replace() 给了我Fat string Text.str_ireplace() 给了我`字符串文本。`。您确定要向我们展示实际代码吗?

标签: php str-replace


【解决方案1】:

这与“胖字符串文本”相呼应。

您的 PHP 安装可能有误或您发布的代码与您正在运行的程序不完全匹配

另外,str_ireplace 回显 “字符串文本”

【讨论】:

  • 找到了问题..我数组中的一些单词就像->我已经,不能
  • 是的,避开你的撇号:)
【解决方案2】:

无法在 PHP 5.3.3 上重现。我明白了:

php > $str ="Fat string of Text.";
php > $commonwords = array('fat','of','random');
php > $cleantext = str_replace($commonwords,'',$str);
php > echo $cleantext;
Fat string  Text.
php > $cleantext = str_ireplace($commonwords,'',$str);
php > echo $cleantext;
 string  Text.

正如预期的那样。

【讨论】:

    猜你喜欢
    • 2014-02-17
    • 1970-01-01
    • 2022-01-18
    • 2019-01-03
    • 2011-09-24
    • 2019-03-31
    • 2021-10-20
    • 2014-02-25
    • 1970-01-01
    相关资源
    最近更新 更多