Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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_Regex - Fatal编程技术网

PHP正则表达式:替换两个特殊字符之间的子字符串

PHP正则表达式:替换两个特殊字符之间的子字符串,php,regex,Php,Regex,更新问题: $li_text = $li->plaintext; echo '<br>'.$li_text; echo '<br>'.$li_text = preg_replace('/\:(.*?)\>/',':', $li_text); 如果我分配了$li_text=“资格:学校和毕业>BE/B.技术(工程)”,则正则表达式工作正常。试试这个: preg_replace('/(?<=:)(.*?)>/', '', $str); preg_替

更新问题:

$li_text = $li->plaintext;
echo '<br>'.$li_text;
echo '<br>'.$li_text = preg_replace('/\:(.*?)\>/',':', $li_text);
如果我分配了
$li_text=“资格:学校和毕业>BE/B.技术(工程)”
,则正则表达式工作正常。

试试这个:

preg_replace('/(?<=:)(.*?)>/', '', $str);
preg_替换(“/(?/”,“$str”);

您的代码运行正常。请注意,
preg\u replace
不会更改主题(即
$str
),但会返回结果

preg_replace()如果subject参数是数组,则返回一个数组, 或者一根绳子

如果找到匹配项,将返回新的主题,否则返回 主题将不加更改地返回,如果发生错误,则返回NULL

因此:

是错误的,但是:

$str = preg_replace('/:(.*?)\>/',':', $str);

echo $str;

有效吗?

你确定吗?我刚刚测试了它们,它们工作得很好。你是否将
preg\u replace
的返回值赋回到
$str
?(不得不问;有时是简单的事情)@dleiftah我想就是这样的。
preg_replace('/:(.*?)\>/',':', $str);

echo $str;
$str = preg_replace('/:(.*?)\>/',':', $str);

echo $str;