我有这个字符串:
text example (some text) (usb, apple (fruit), computer (technology), nature: sky)
我需要var_dump()
输出explode "("
:
array(3) {
[0]=>
string(34) "text example"
[1]=>
string(12) "some text"
[2]=>
string(12) "usb, apple, computer, nature: sky"
}
答案 0 :(得分:0)
您可以使用带有正则表达式模式的php函数link
删除您不希望在输出中显示的文本,然后使用preg_replace()
函数:
explode
结果:
$string = 'text example (some text) (usb, apple (fruit), computer (technology), nature: sky)';
//Remove (fruit) and (technology) from string
$newString = preg_replace('/ \((\w+)\)/i', ', ', $string);
//Explode with new string
$output = explode(" (",$newString);
//Remove ')' from output
var_dump(preg_replace('/\)/i', '', $output));
希望这会有所帮助。