|
Posted by azriley on 02/15/06 21:07
could use some help with a function to clean up keywords in a url. I'm
expecting $keywords to equal 'coretta scott king' - the plus signs are
stripped out for search engine referrals. What am I doing wrong?
<?php
$referer = 'http://www.google.com/search?hl=en&q=coretta+scott+king';
function parse_keywords($referer){
// Google, AllTheWeb, MSN, Freeserve, Altavista
if ((eregi("www.google",$referer)) or
(eregi("www.alltheweb",$referer)) or (eregi("search.msn",$referer)) or
(eregi("ifind.freeserve",$referer)) or
(eregi("altavista.com",$referer))) {
preg_match("'q=(.*?)(&| )'si", " $url ", $keywords);
}
// HotBot, Lycos, Netscape, AOL
if ((eregi("www.hotbot",$referer)) or (eregi("search.lycos",$referer))
or (eregi("search.netscape",$referer)) or
(eregi("aolsearch.aol",$referer))) {
preg_match("'query=(.*?)(&| )'si", " $url ", $keywords);
}
// Yahoo
if ((eregi("yahoo.com",$referer)) or (eregi("search.yahoo",$referer)))
{
preg_match("'p=(.*?)(&| )'si", " $url ", $keywords);
}
// Looksmart
if (eregi("looksmart.com",$referer)) {
preg_match("'key=(.*?)(&| )'si", " $url ", $keywords);
}
// DMOZ
if (eregi("search.dmoz",$referer)) {
preg_match("'search=(.*?)(&| )'si", " $url ", $keywords);
}
// Ask
if (eregi("ask.co",$referer)) {
preg_match("'ask=(.*?)(&| )'si", " $url ", $keywords);
}
if (($keywords[1]!="") and ($keywords[1]!=" ")) {
$keywords=str_replace("+"," ",$keywords[1]);
}
return $keywords;
}
$keywords = parse_keywords($referer);
echo $keywords;
?>
[Back to original message]
|