我有这样的表达:
$x="We have a cat here.";
我想用例如 5 替换“a”,所以应该如下所示:
We have 5 cat here. //It doesn't make sense, but it's just an example.
我试过简单
echo str_replace("a","5",$x);
但那又回来了
We h5ve 5 c5t here.
然后,我尝试了
echo str_replace(" a "," 5 ",$x);
但这对像这样的字符串不起作用
We have a cat here. (A dog actually).
我决定使用正则表达式,但我完全是新手,我不知道如何使用它们中的任何一个......好吧,我真的很感谢任何指向一个好的教程的链接,但我需要很快得到答案。 ..