Re: RegExp for preg_split()

From: Date: Sat, 29 Apr 2006 01:24:34 +0000
Subject: Re: RegExp for preg_split()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-235054@lists.php.net to get a copy of this message
Weber Sites LTD wrote:
Hi I'm looking for the RegExp that will split a search string into search keywords. while taking " " into account.
From what I managed to find I can get all of the words into an array but I
would like all of the words inside " " to be in the same array cell.
You want to use preg_match_all, not preg_split: $String = 'Medaillons, Listels, "custom stuff", "more things", entryway, accents, showplace'; $MyRegEx = '/"[^"]+"|[^"\s,]+/'; preg_match_all($MyRegEx, $String, $Tokens); echo '<pre>'; var_dump($Tokens); produces: array(1) { [0]=> array(7) {
    [0]=>
    string(10) "Medaillons"
    [1]=>
    string(7) "Listels"
    [2]=>
    string(14) ""custom stuff""
    [3]=>
    string(13) ""more things""
    [4]=>
    string(8) "entryway"
    [5]=>
    string(7) "accents"
    [6]=>
    string(9) "showplace"
} }

« previous php.general (#235054) next »