修剪php中的一部分字符串[复制]

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);
?>