Re: Re: preg_split
| From: | Google Kreme | Date: | Fri, 03 Nov 2006 22:38:11 +0000 |
| Subject: | Re: Re: preg_split | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244188@lists.php.net to get a copy of this message | ||
On 03 Nov 2006, at 12:32 , Myron Turner wrote:
1. A preg_ expression has to have the delimeters '/^([^,]+),\s?(.*)/'.Ah, well, that would make a difference. <http://akane.covisp.net/~kreme/vonage.phps> <http://akane.covisp.net/~kreme/vonage.php> $cid[$i]=preg_split('/^([^,]+),\s?(.*)/', $line, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); Now it has an extra field in the array, but at least it is splitting the line.
[6] => Array
(
[0] => (555) 555-5556
[1] => Maggie, Fred, and George Cell
[2] =>
)
2. Why do you need this complex expression to split at a comma? This '/,/' would do the trick. And even simpler explode(',', $line);Because I need to split only at the FIRST comma.
Also your regex ^([^,]+) asks the perl regex parser to find the beginning of a line at which there is one or more instances of NO Comma. That is, [^ ] is a negation, so that [^0-9] means do not match any numbers.Yes, and ^([^,]+) means, From the start of the line, get 1 or more characters that are not a comma and put them in \01.
So that any possible split would gobble up everything after the first instance in which the beginning of a line did not start with a comma, which would mean that you would get null results.No, that's not right at all. As I said, the regex works (and has been tested in other ways).
3. Is there a reason why you are using the flag PREG_SPLIT_DELIM_CAPTURE?I tried many different variations. -- It's better to burn out than it is to rust -- Neil Young as quoted by Kurt Cobain