简体   繁体   English

是否有原因str_replace不适用于该短语

[英]Is there a reason str_replace doesn't work on this phrase

I am trying to replace the following text 我正在尝试替换以下文本

options":{"icon": "color.php?tx=31c}, 选项“:{” icon“:” color.php?tx = 31c},

into 进入

options":{"icon": "color.php?tx=31*}, 选项“:{” icon“:” color.php?tx = 31 *},

basically removing the 'c' and replacing it with an asterisk and the php function i'm using is as simple as a str_replace. 基本上删除'c'并将其替换为星号,而我正在使用的php函数就像str_replace一样简单。 So my code is as follow 所以我的代码如下

$str = 'options":{"icon": "color.php?tx=31c},';
$newStr = str_replace("c},","*},",$str);

but for some reason when i echo $newstr, the str_replace didn't replace anything. 但是由于某些原因,当我回显$ newstr时,str_replace没有替换任何内容。 I tried with just c, it works. 我只是用c尝试过,它有效。 I tried with just the }, it works. 我只尝试了},就可以了。 But not together. 但是不能在一起。 Anyone has any idea? 有人知道吗?

Semicolon (;) missing on first line. 第一行缺少分号(;)。 Should be: 应该:

$str = 'options":{"icon": "color.php?tx=31c},';
<?php

$str = 'options":{"icon": "color.php?tx=31c},';
$newStr = str_replace("c},","*},",$str);
echo $newStr;

This code works perfectly for me. 这段代码非常适合我。 See this link : https://ideone.com/wOTb8V 看到这个链接: https : //ideone.com/wOTb8V

As you can see, the output is options":{"icon": "color.php?tx=31*}, 如您所见,输出为options":{"icon": "color.php?tx=31*},

Maybe you are trying to echo $str instead of $newStr ? 也许您正在尝试回显$str而不是$newStr

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM