Preg#u替换';短代码';在php中
我得到了一个包含[center](带方括号)的字符串,然后需要用另一个字符串替换它。我确信使用preg_replace一定有办法做到这一点,但无法使其正常工作正则表达式对于这样的任务来说太过简单了,使用 你喜欢这样吗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
<?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;
?>