我需要=用==符号替换字符串。问题是我不想替换<=和>=签名。
1 回答
Qyouu
TA贡献1786条经验 获得超11个赞
你可以使用preg_replace这个正则表达式,它看起来对=未通过前面的迹象<,>,!或=或之后=:
(?<![<>=!])=(?!=)
例如:
$string = "I need to replace = in string with == sign, but not in <=, != and >= signs.";
echo preg_replace('/(?<![<>=!])=(?!=)/', '==', $string);输出:
I need to replace == in string with == sign, but not in <=, != and >= signs.
- 1 回答
- 0 关注
- 238 浏览
添加回答
举报
0/150
提交
取消
