2010-09-09 2 views

ответ

45

Explode не может этого сделать. Для этого есть хорошая функция, называемая preg_split. Делают это так:

$keywords = preg_split("/[\s,-]+/", "This-sign, is why we can't have nice things"); 
var_dump($keywords); 

Воспроизводит:

array 
    0 => string 'This' (length=4) 
    1 => string 'sign' (length=4) 
    2 => string 'is' (length=2) 
    3 => string 'why' (length=3) 
    4 => string 'we' (length=2) 
    5 => string 'can't' (length=5) 
    6 => string 'have' (length=4) 
    7 => string 'nice' (length=4) 
    8 => string 'things' (length=6) 

BTW, не используйте split, это устаревшее.