php删除花括号和内部检索剩余的内容

时间:2015-06-11 12:01:45

标签: php string

删除包含大括号的大括号内的php字符串的特定文本,它应该删除....

数据字符串如下所示......

{page:header}
this text should not be removed
{menu_list:menu_list_2}
this text should not be removed
{page:footer}

想要删除大括号内的文字以及花括号......

想要这样的数据......

this text should not be removed
this text should not be removed

1 个答案:

答案 0 :(得分:0)

使用正则表达式,

$text='{page:header}
this text should not be removed
{menu_list:menu_list_2}
this text should not be removed
{page:footer}'
$data = preg_replace("/\{[^}]+\}/", "", $text);
print_r($data); // answer will be as follow
this text should not be removed
this text should not be removed