繁体   English   中英

php删除大括号和里面的内容检索剩余

[英]php remove curly braces and content inside retrieve remaining

想要删除大括号内的 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

使用正则表达式,

$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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM