Answer the question
In order to leave comments, you need to log in
How to remove the content of curly braces in php?
Hello !
Please tell me - how to remove the contents of curly braces in php along with brackets.
For example, there is a variable
$str='текст_полезный{{текст_текст{{текст_внутри скобки}}дальше_текст}}_снова полезный текст';
function del_figurn ($stroka)
{
$p1=strpos($stroka, '{{');
$p2=strpos($stroka, '}}');
// строка {{ ... }} без кавычек
$podstroka = substr($stroka, $p1+2, $p2-$p1);
//echo ($podstroka.'<br><br>');
if (strpos($podstroka, '{{')!==false){
$pppos=strpos($podstroka, '{{')+1;
$vnutr=substr($podstroka, $pppos-1, $p2-$p1);
$stroka=str_replace ($vnutr, '', $stroka);
} else $stroka=substr_replace($stroka,'', $p1, ($p2-$p1)+2);
//echo($stroka);
return($stroka);
}
Answer the question
In order to leave comments, you need to log in
$str = "текст_полезный{{текст_текст{{текст_внутри скобки}}дальше_текст}}_снова полезный текст";
$str = preg_replace("/\\{.+\\}/m","",$str);
Regular expressions and the preg_replace() function will come to your rescue.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question