i have 1000+ emails separated with commas, so i need to split them.., but i have one simple doubt...!!! we have explode and preg_split, which is best.., i believe both are same $res = explode(' , ', $emails) or $res = preg_split('/\s*,\s*/', $email); PHP: And may i know preg_split have ' \s*,\s* ' but explode have nothing...!!! Would be greatful to your help..!!!!
explode() is indefinitely better in this situation because it costs less. preg_split is a regular expression function which will spend extra server resources to parse the regexp string you have provided, namely '/\s*,\s*/'.
My guess would be explode, but before you commit one way or the other, you might want to think about taking a bit of time and try out both methods using timers, allowing you to make a reasoned decision based on performance metrics given your situation and not merely speculation.
$res = explode(' , ', $emails) PHP: ^ Explode would match (space)(comma)(space) $res = preg_split('/\s*,\s*/', $emails); PHP: ^ Whereas the above preg_split() would match (new-line)(comma)(new-line) New-line as in any new-line/whitespace character (space, \n, \r\n, \t) So the best option out of the two in your scenario would be, are you wanting to match new-line(s) then go for the preg_replace(), or if your just wanting to match space(s) then go for the explode().
But danx, $string = 'one ok , two,three, four , five,six seven'; $array = preg_split("/\s*,\s*/", $string); print_r($array); PHP: and $string = 'one ok , two,three, four , five,six seven'; $array = preg_split("/,/", $string); print_r($array); PHP: Giving the same out put, Array ( [0] => one ok [1] => two [2] => three [3] => four [4] => five [5] => six seven ) then what is the necessary of \s*,\s*, would be grateful about your help..!!