Is there a way i can split the items in a string into seperate vars .. $string= "> Cat 1 > subcat 1 > subcat 2" into
thanks for any help
You could consider using explode. Something like this:
Note that this might result in $my_array having a values with just spaces in them and the other slots having values with a space before and/or after. You'd need to loop through the array and clean it up a bit.
$string= "> Cat 1 > subcat 1 > subcat 2";
$my_array = explode(">", $string);
High Energy Magic Dept.
If you want to get rid of any excess white space, but cannot always be sure if it will be there, preg_split() can be useful, too:
$parts = preg_split('/\s*>\s*/', $string, null, PREG_SPLIT_NO_EMPTY);
// last arg so leading ">" does not create empty element
Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett
"But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because he’s a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)