Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:如何替换=仅替换而不替换<;=及>=_Php_String_Replace - Fatal编程技术网

PHP:如何替换=仅替换而不替换<;=及>=

PHP:如何替换=仅替换而不替换<;=及>=,php,string,replace,Php,String,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.";
echo preg_replace('/(?<![<>=!])=(?!=)/', '==', $string);
$string=“我需要将字符串中的=替换为==符号,而不是in=符号。”;
echo preg_替换('/(?=!])=(?!=)/'、'=='、$string);
输出:

I need to replace == in string with == sign, but not in <=, != and >= signs.
我需要将字符串中的==替换为==符号,而不是in=符号。

我们可以假设
=
周围有空格,还是不存在
=
?如果您将您的代码尝试发布为一个。谢谢。@MohamadMTEYREK不用担心。我很高兴能帮上忙。