我需要=用==符號替換字符串。問題是我不想替換<=和>=簽名。
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 關注
- 222 瀏覽
添加回答
舉報
0/150
提交
取消