Convert a complicated string into an array in php
Posted
by Patrick Beardmore
on Stack Overflow
See other posts from Stack Overflow
or by Patrick Beardmore
Published on 2009-12-18T19:34:02Z
Indexed on
2010/04/07
11:33 UTC
Read the original article
Hit count: 228
I have a php variable that comes from a form that needs tidying up. I hope you can help.
The variable contains a list of items (possibly two or three word items with a space in between words). I want to convert it to a comma separated list with no superfluous white space. I want the divisions to fall only at commas, semi-colons or new-lines. Blank cannot be an item.
Here's a comprehensive example (with a deliberately messy input):
Variable In: "dog, cat ,car,tea pot,, ,,, ;;(++NEW LINE++)fly, cake"
Variable Out "dog,cat,car,tea pot,fly,cake"
Can anyone help?
© Stack Overflow or respective owner