Search parser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Search parser

Post 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);
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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)}
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

this may help you in isolating the query part of the url: http://www.php.net/manual/en/function.parse-url.php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post by Kriek »

This should speed up the process quite a bit. Thanks guys!
Post Reply