Re: RegExp for preg_split()

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

 



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"
  }
}

--
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