This question already has an answer here:
I have a string in a variable like this:
$var = "This is a banana (fruit)";
How do I trim / get the part 'fruit' only? (i.e., data inside braces whatever it is).
</div>
Try this:
<?php
$sentence = "This is a banana (fruit)";
$a = stripos($sentence,"(");
$b = stripos($sentence,")");
echo substr($sentence, $a, $b);
?>
Use preg_rpelace function:
<?php
$str = "This is a banana (fruit)";
echo preg_replace('/.*\((.*)\).*/','$1',$str);
?>