如何替换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


来源:https://www.codenong.com/4283044/

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?