Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用我已经拥有的以下代码:
$var = "City 0.428371 2 BEIJING Beijing 39.91388888888889 116.39166666666667 Organization 0.392154 1 PBOC PBOC Motorsports Club Company 0.38134 1";
需要提取这个:
城市 0.428371 2 北京
你尝试了什么?
这似乎可以解决问题:
$parts = explode(' ', $var, 5); array_pop($parts);
$extracted = implode(' ', array_slice(explode(' ', $var), 0, 4));
北京必须是一个词,例如,不能与“纽约”一起使用。