如何替换php中的字符串

how to replace a string in php

我想替换 \'\' 登录字符串。
例如

1
2
3
$str = 'if x<y and y>z';
echo str_replace( '<', 'something', $str ) ."
"
;

这给出以下结果

1
if xsomethingy and y>z

我的问题是如何将 \'>\' 替换为文本 \'something\'


1
str_replace( array('<', '>'), 'something', $str )

有可能,见手册

相关讨论

  • 我应该如何将 \'>\' 替换为其他文本而不是具体 \'something\'
  • 和 \'<\' 应该替换为 \'something\'
  • 感谢 RC 我已经通过使用 str_replace(array(\'<\',\'>\'),array(\'

签出preg_replace()

文档在这里 http://php.net/manual/en/function.preg-replace.php

例子是
preg_replace('/[<>]/', 'something', $str);


preg_replace(/[<>]/g, 'something', $str)

你需要学习一些 PHP 呀
http://php.net/manual/en/function.preg-replace.php


以上是如何替换php中的字符串的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>