如果我有一個像如何爆炸只有一次在PHP
「1234名額外」
一個字符串,我也
list($postcode, $city) = explode(" ", $string);
事實證明,$區號爲「1234」 $ city是「Name」。我想$ city是「Name Extra」
我該怎麼做?
如果我有一個像如何爆炸只有一次在PHP
「1234名額外」
一個字符串,我也
list($postcode, $city) = explode(" ", $string);
事實證明,$區號爲「1234」 $ city是「Name」。我想$ city是「Name Extra」
我該怎麼做?
使用爆炸的第三個參數($限制)。結果數組將有$ limit元素。
list($postcode, $city) = explode(" ", $string, 2);
如果你看看PHP docs,你會發現explode()
有一個可選的第三個參數,它指定了你想要爆炸的次數。
從手冊:
array explode (string $delimiter , string $string [, int $limit ])
所以你使用可選的限制參數,你的情況2,我相信
考慮使用正則表達式來確定什麼是什麼。 http://php.net/manual/en/function.preg-replace.php –
http://www.php.net/manual/en/function.explode.php – jackdoe