Re: Split string
| From: | Lester Caine | Date: | Wed, 02 May 2007 09:55:51 +0000 |
| Subject: | Re: Split string | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254221@lists.php.net to get a copy of this message | ||
Fredrik Thunberg wrote:
Lester Caine skrev:I'm glad I asked now, that is a lot nicer than trying to get the preg_split thing working :) -- Lester Caine - G8HFL ----------------------------- Contact - http://home.lsces.co.uk/lsces/wiki/?page=contact L.S.Caine Electronic Services - http://home.lsces.co.uk MEDW - http://home.lsces.co.uk/ModelEngineersDigitalWorkshop/ Firebird Foundation Inc. - http://www.firebirdsql.org/index.phpCan someone with a few more working grey cells prompt me with the correct command to split a string. The entered data is names, but I need to split the text up to the first space or comma into one string, and the rest of the string into a second. It's the 'first either space or comma' that eludes me at the moment :( In know it's probably obvious, but it always is when you know the answer.$myString = "John Doe"; $pos = strpos($myString, " ") < strpos($myString, ",") ? strpos($myString, " ") : strpos($myString, ","); $part1 = substr($myString, 0, $pos); $part2 = substr($myString, $pos);