我有例如:“颜色(黄色)”
我想获得“颜色”
所以我做了:
$driver_bo = explode('/\\(', $driver);
$driver = trim($driver_bo[0]);
$driver_bo = explode('/(', $driver);
$driver = trim($driver_bo[0]);
$driver_bo = explode('(', $driver);
$driver = trim($driver_bo[0]);
Ant没有任何效果
答案 0 :(得分:1)
Rizer123是对的。试试这个:
$driver = "Color (YELLOW)";
$driver_bo = explode('(', $driver);
$driver = trim($driver_bo[0]);
echo($driver);
输出为" Color"
答案 1 :(得分:0)
在这种情况下,您可以使用两种不同的功能。
$driver = "Color (YELLOW)";
$driver_bo = explode('(', $driver);
$driver = trim($driver_bo[0]);
var_dump($driver);
$driver = "Color (YELLOW)";
preg_match('/(.*?)\(.*?\)/si', $driver, $driver_bo);
$driver = trim($driver_bo[1]);
var_dump($driver);
他们都返回“颜色”。