I have Three word . But i need only those word which is in { } Like:
text1 {text2} text3
get the text only in { }
Result = text2
And
result = text1 text3 (remove {} word )
and
from text1 {text2} text3 {text4}
result = text2 and text4
I have Three word . But i need only those word which is in { } Like:
text1 {text2} text3
get the text only in { }
Result = text2
And
result = text1 text3 (remove {} word )
and
from text1 {text2} text3 {text4}
result = text2 and text4
Try preg_match_all for this :
$a = 'text1 {text2} text3';
preg_match_all("/\\{(.*?)\\}/", $a, $matches);
print_R($matches[1][0]);
output will be:
text2
One solution would be loop through each character. If character is { then start collecting characters into word variable. If you find } character, then finish - you have a word.
with regex:
$search = 'text1 {text2} text3';
preg_match('#\{(.*)\}#', $search, $match);
echo $match[1];
see preg_match doc