Go Back   WebMasters.org Forums > Website Design & Development > PHP Forum

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-2010, 08:14 AM
Junior Member
 
Join Date: Mar 2010
Posts: 10
Default Is preg_split() the best choice for this?

Working on search engine functionality and I'm trying to handle queries that contain matched quotes.

Example:
input: foo , output: " AND x LIKE '%foo%'"
input: foo bar , output: " AND x LIKE '%foo%' AND x LIKE '%bar%'"
input: "foo bar" , output: " AND x LIKE '%foo bar%'"

At the moment I'm splitting the search string by a space then looping through each word and just building a straight up "AND x LIKE..." string which gets appended to the final query I run. It takes a lot of logic just using explode() to handle the quotes correctly, there has to be a better way.

Perhaps using preg_split() would be a better alternative? I don't use regexs too often so I'm not really sure if this is even possible, thoughts?

The end result would be getting an array of terms. In the above example the array should be:

0 = foo
1 = foo
2 = bar
3 = foo bar

Or if this is more clear:

User searches for: foo bar

Array would be:

0 = foo
1 = bar

User searches for: "foo bar"

Array would be:
0 = foo bar

User searches for: foo "foo bar"

Array would be:
0 = foo
1 = foo bar
__________________
Bodyboarding | Bodyboarding
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-07-2010, 05:04 AM
Junior Member
 
Join Date: Apr 2010
Posts: 1
Default hai

Try explode(' ', $input);
__________________
ac compressor
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2010, 01:45 AM
Senior Member gay
 
Join Date: Mar 2010
Posts: 356
Default

Wow! I’ve never heard of this before and I think they’re awesome!
__________________
I have been looking for mbt shoes, I often use the bad results will often buy a new.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:21 PM.



Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
vB Ad Management by =RedTyger=