Jump to content

regex for preg_split ?


feha

Recommended Posts

Hi

I do have a problem with extracting into array search input keywords ...

 

I use:

$keywords = preg_split('/[\s,]+/', $keywords);

 

to split input keywords ...

it works o.k. with spaces etc ...

 

I do have a problem with phrase search  ...

 

example:

 

me and "my friends" or you and "your friends"

 

Is split o.k. but i do not want to split the word within quotes ...

 

the word within the quotes should not split in to  "my  ....  friends" this makes problems with MySQL query when searching phrases ...

 

the array:

Array ( [0] => me [1] => and [2] => "my [3] => friends" [4] => or [5] => you [6] => and [7] => "your [8] => friends" )

 

I'm not good in RegEx-es any help would be appreciated ...

 

The expression

'/"(.*?)"/'

can extract the content within double quotes but i can't combine it with preg_split.

 

 

Link to comment
https://forums.phpfreaks.com/topic/91288-regex-for-preg_split/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.