Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- split keywords into array
- Geoff Berrow
July 24, 2007, 4:11 pm
rate this thread
an array, assuming the text can be separated by any non alphanumeric
$string ="cat,dog fish, mouse -elephant/tiger";
 => cat
 => dog
 => fish
 => mouse
 => elephant
 => tiger
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Re: split keywords into array
$array = preg_split('/\W+/',$string,-1,PREG_SPLIT_NO_EMPTY);
\W = non-word character
"A "word" character is any letter or digit or the underscore character, =
that is, any character which can be part of a Perl "word". The definitio=
of letters and digits is controlled by PCRE's character tables, and may =
vary if locale-specific matching is taking place. For example, in the "f=
(French) locale, some character codes greater than 128 are used for =
accented letters, and these are matched by \w."