Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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,如何删除php中的所有[]标记。所以[/B][CUT],…使用 我想你得用这个 要做到这一点…您需要为此使用正则表达式,使用: $processed然后包含“foo bar” $string = 'foo [/B] [CUT] bar'; $pattern = '/\[\/?[A-Z]+\]/'; $processed = preg_replace($pattern, '', $string); 这假设标签将始终包含大写字母,并且在标签名称前面可能有一个/。我认为op想要做的不仅是删除括号,还

如何删除php中的所有[]标记。所以[/B][CUT],…

使用

我想你得用这个


要做到这一点…

您需要为此使用正则表达式,使用:

$processed
然后包含“foo bar”

$string = 'foo [/B] [CUT] bar';
$pattern = '/\[\/?[A-Z]+\]/';
$processed = preg_replace($pattern, '', $string);

这假设标签将始终包含大写字母,并且在标签名称前面可能有一个
/

我认为op想要做的不仅是删除括号,还删除括号内的所有内容。IE,删除标记。George这不是删除[]及其value@onteria_是的,在这种情况下stru_replace不会起作用。公平地说,这个问题没有明确说明所需的输出。@Tomalak肯定是这样的。“所以[/B][CUT],…”以防万一,如果标签可以包含小写字母,只需在
$pattern
中将
[A-Z]
更改为
[A-zA-Z]
str_replace (array('[', ']'), '', your text here)
$string = 'foo [/B] [CUT] bar';
$pattern = '/\[\/?[A-Z]+\]/';
$processed = preg_replace($pattern, '', $string);
'foo bar'