str_replace 只返回大写字母

发布于 2024-09-17 20:04:07 字数 403 浏览 3 评论 0原文

我这里有一个小问题..我使用 str_replace 来替换最常见的单词..并且由于某种原因它替换了除大写字母之外的每个字母。

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

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

echo $cleantext;

它会回显..F T

任何想法我做错了什么.. 预先感谢

,哦..我尝试了 str_ireplace.. 但没有任何结果

i have a lil problem here..i'm using str_replace to replace the most common words..and for some reason its replacing every letter except caps.

for example..if i had the code below

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

echo $cleantext;

it would echo.. F T

any ideas what i did wrong..
thanks in advance

and oh..i tried str_ireplace.. but nothing

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

澜川若宁 2024-09-24 20:04:07

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

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

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

This echos "Fat string Text".

Your PHP installation may be wrong or your posted code that does not exactly match the program you are running

Also, str_ireplace echos "string Text".

别理我 2024-09-24 20:04:07

无法在 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.

正如预期的那样。

Can't reproduce that on PHP 5.3.3. I get:

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.

as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文