Re: Re: preg_split

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux