explode() - delimiting using comma OR space OR both
Posted: Sat Sep 01, 2007 12:32 am
Hi in an application i am working i require some tags (similar to flickr tags)
if the user enters tag:love,life,success
then i use to remove the tags string and put in an array each value and process. Delimited by comma
Now if the user writes tags: love ,life , success then the regex allows spaces and commas in addition to alphanumeric data.
Is there any way/solution such that i can explode (split a string) with delimiter comma OR space instead of just a comma as in
"," delimits using only a comma
" " delimits using only a space
If there is space then also the array should be split. If there is a comma then also the array should split. And if there is a combination or comma space then too array should be split
Is there anyway i can check what is the delimiter either , or space or both and accordingly i can proceed?
if the user enters tag:love,life,success
then i use
Code: Select all
$wordlist=explode(",",$tags);Now if the user writes tags: love ,life , success then the regex allows spaces and commas in addition to alphanumeric data.
Is there any way/solution such that i can explode (split a string) with delimiter comma OR space instead of just a comma as in
Code: Select all
$wordlist=explode(",",$tags);"," delimits using only a comma
Code: Select all
$wordlist=explode(" ",$tags);" " delimits using only a space
If there is space then also the array should be split. If there is a comma then also the array should split. And if there is a combination or comma space then too array should be split
Is there anyway i can check what is the delimiter either , or space or both and accordingly i can proceed?