Page 1 of 1

Search parser

Posted: Tue Jan 21, 2003 9:55 pm
by Kriek
I've been working on a little snippet to work in conjunction with my referral script. I've been trying to determine the easiest method to parsing search engine urls from primarily Google, but in the future I may need to it to work with Yahoo or other search engines.

I need to take something similar to this:

"http://www.google.com/search?hl=en&lr=& ... =jon+kriek"

And turn it into this:

"Google Search: Jon Kriek"

I thought of using eregi_replace() to narrow the search url down to "Google Search", but is it possible to pull the search terms or key works "Jon Kriek" from the search url using eregi_replace() or would something like split() work better? Since search engines use "+" for spacing.

Example: $search=split(' ',$sterms);

Posted: Tue Jan 21, 2003 10:10 pm
by hob_goblin
I'd use reg exps to isolate it. then str_replace to change things like the +'s to spaces.

I'm not sure about the actual expression itself but some pseudo code would be like


{any thing ending starting with http:// and ending with q=}{actual message, only things like A-Za-z0-9, periods, asteriks, etc}{maybe an & sign and another variable (very unlikely)}

Posted: Tue Jan 21, 2003 10:16 pm
by mydimension
this may help you in isolating the query part of the url: http://www.php.net/manual/en/function.parse-url.php

Posted: Tue Jan 21, 2003 10:57 pm
by volka

Posted: Wed Jan 22, 2003 1:58 pm
by Kriek
This should speed up the process quite a bit. Thanks guys!