例如,这是我的字符串:
$text = "Iphone 4, Iphone 4S; Iphone 5, Iphone 3. Iphone 3S";
并拆分字符串:
$splitting_strings = array(".", ";", ".");
$result = array (
0 => "Iphone 4",
1 => "Iphone 4S",
2 => "Iphone 5",
3 => "Iphone 3",
4 => "Iphone 3S"
);
我正在使用这段代码:
$regex = '/(' . implode('|', $splitting_strings) . ')/';
print_r(implode($regex, $text));