我有一些PHP代码,它从一些javascript收集用于访问我的网站的关键字并将它们存储到数据库中,这一切都正常,除了它错过了关键字字符串末尾的最后一个字母,例如如果关键字是示例,它将获得例子。
//Get keywords from reffering website
function getReferalHost()
{
$ref = parse_url( $_GET['self'] );
$refer = $ref['host'];
return $refer;
}
function getKeywords()
{
$refer = str_replace( '%2520' , '+' , urlencode( $_SERVER['REQUEST_URI'] ) );
$refer = str_replace( '%26' , '&', $refer );
$refer = str_replace( '%3D' , '=', $refer );
$host_ref = parse_url( $_GET['self'] );
$host = $host_ref['host'];
if(stristr($host,'google.'))
{
//do google stuff
$match = preg_match('/&q=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$rep = str_replace('&q=','',$querystring);
$querystring = substr( $rep , 0 , ( strlen( $rep ) - 1 ) );
$keywords = explode('+',$querystring);
return $keywords;
}
elseif(stristr($host,'yahoo.'))
{
//do yahoo stuff
$match = preg_match('/p=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$rep = str_replace('p=','',$querystring);
$querystring = substr( $rep , 0 , ( strlen( $rep ) - 1 ) );
$keywords = explode('+',$querystring);
return $keywords;
}
elseif( stristr($host,'msn.') or stristr($host,'bing.') or stristr($host, 'ask.com' ) )
{
//do msn stuff
$match = preg_match('/q=([a-zA-Z0-9+-]+)/',$refer, $output);
$querystring = $output[0];
$rep = str_replace('q=','',$querystring);
$querystring = substr( $rep , 0 , ( strlen( $rep ) - 1 ) );
$keywords = explode('+',$querystring);
return $keywords;
}
}
define('DELIMITER' , ' ');
$request_uri = getReferalHost();
$keys = getKeywords();
$query_string = "";
foreach( $keys as $key ){
$query_string .= $key.DELIMITER;
}
我们非常感谢任何建议。
由于
利
答案 0 :(得分:0)
$querystring = substr( $rep , 0 , ( strlen( $rep ) - 1 ) );
在所有情况下,您是否尝试删除该行?
答案 1 :(得分:0)
删除此行:
$querystring = substr( $rep , 0 , ( strlen( $rep ) - 1 ) );
然后,更改此行:
$keywords = explode('+',$querystring);
要:
$keywords = explode('+',$rep);