Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search string parse...

Status
Not open for further replies.

skiflyer

Programmer
Joined
Sep 24, 2002
Messages
2,213
Location
US
Disclaimer... this is me being busy and not having time to tackle this right away so if you don't have something readily available I'll get to it soon and post it here...

I'm looking for a regex to parse a search string google style... right now I'm using
Code:
  $words = preg_split('/[\s,]+/', $search_string);

But I'd like to add support for phrases enclosed in quotes..

Thanks,
Rob
 
Talk about pushed to the back burner... (I almost couldn't believe the original post date on this)

Code:
$keyword_string='some "input from" a form';
$pattern = '/"(.*?)"/';
$phrase_count = preg_match_all($pattern, $keyword_string, $phrase_matches);
array_shift($phrase_matches);
$keywords_remaining=preg_replace($pattern, '', $keyword_string);

You'll be left with alot of whitespace or delimiters in your search string, but that's easy enough to clean up later.

Enjoy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top