2010-09-09 4 views

Répondre

45

Explode ne peut pas faire cela. Il y a une bonne fonction appelée preg_split pour cela. Faites comme ceci:

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

Ce sorties:

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, ne pas utiliser split, il est dépréciée.

Questions connexes