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);
Search parser
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
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)}
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)}
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
this may help you in isolating the query part of the url: http://www.php.net/manual/en/function.parse-url.php
also http://www.php.net/manual/en/function.parse-str.php and you have all you need