我想替换 \\'<\\' 和 \\'>\\' 登录字符串。
例如
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中的字符串
转载请保留出处和原文链接:https://www.cnhackhy.com/158225.htm