Creating arrays with explode()

Hello,
mails are separated by commas, some have spaces but some don’t
How can I fix this problem

$str = ‘mail,mail,mail, mail, mail, mail, mail’;

print_r (explode(", ",$str));

Output:
Array ( [0] => mail,mail,mail [1] => mail [2] => mail [3] => mail [4] => mail )

Explode the data on the commas.

Then trim the array of data after you have exploded it.

You can do both of these in a single statement -

$result = array_map('trim', explode(',',$str));

Thank you very much, I could never think like that

Sponsor our Newsletter | Privacy Policy | Terms of Service