Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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
Preg#u替换';短代码';在php中_Php - Fatal编程技术网

Preg#u替换';短代码';在php中

Preg#u替换';短代码';在php中,php,Php,我得到了一个包含[center](带方括号)的字符串,然后需要用另一个字符串替换它。我确信使用preg_replace一定有办法做到这一点,但无法使其正常工作正则表达式对于这样的任务来说太过简单了,使用 你喜欢这样吗 <?php $a="abc [dfh]124[center]"; $b=preg_replace ('/\[(.*?)\]/s','[replace]', $a); // this will replace the string with in the squ

我得到了一个包含[center](带方括号)的字符串,然后需要用另一个字符串替换它。我确信使用preg_replace一定有办法做到这一点,但无法使其正常工作

正则表达式对于这样的任务来说太过简单了,使用

你喜欢这样吗

    <?php

$a="abc [dfh]124[center]";

$b=preg_replace ('/\[(.*?)\]/s','[replace]', $a);   // this will replace the string with in the square brackets

echo $b;

?>

希望这对你有帮助


谢谢。

您不需要正则表达式,只需
str\u replace
显示一些代码即可
    <?php

$a="abc [dfh]124[center]";

$b=preg_replace ('/\[(.*?)\]/s','[replace]', $a);   // this will replace the string with in the square brackets

echo $b;

?>