2010-09-09 14 views

risposta

45

L'esplosione non può farlo. C'è una bella funzione chiamata preg_split per quello. Fare in questo modo:

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

Questo uscite:

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, non usare split, si è deprecato.

Problemi correlati