我在这样的变量中有一个字符串:
$var = "This is a banana (fruit)";
如何修剪/获取部分水果'只要? (即括号内的数据无论如何)。
答案 0 :(得分:1)
试试这个:
<?php
$sentence = "This is a banana (fruit)";
$a = stripos($sentence,"(");
$b = stripos($sentence,")");
echo substr($sentence, $a, $b);
?>
答案 1 :(得分:0)
使用preg_rpelace函数:
<?php
$str = "This is a banana (fruit)";
echo preg_replace('/.*\((.*)\).*/','$1',$str);
?>