我有一个问题是从url字符串获取变量,变量在我测试时总是为空。我在代码中找不到问题。你能帮助我吗 ?非常感谢你
网址字符串示例:
$url_seznam: http://search.seznam.cz/?q=%c5%a1kolen%c3%ad+mistr%c5%af+ve+v%c3%bdrob%c4%9b&sourceid=szn-hp&sgid=qaqnqapauacxumty6e9thnwokswozilikiqbygqjkq%3d%3d&oq=%c5%a1kolen%c3%ad+mistr%c5%af+ve+v%c3%bdrob%c4%9b&aq=-1&thru=&su=e
$url_bing: http://www.bing.com/search?q=scada+academy&go=Odeslat&qs=n&form=QBLH&pq=scada+academy&sc=2-13&sp=-1&sk=&cvid=6c8f027c29a5422a931277ccfc1ddc35
PHP:
if(strpos($_SESSION['ref'], 'seznam.cz')){
$url_seznam = $_SESSION['ref'];
$url_seznam1 = parse_url($url_seznam);
$query = array();
parse_str($url['query'], $query);
$ref_word = $query['q'];
$ref_addr = "Seznam Vyhledávač - ";
$ref_word = str_replace('+',' ',$ref_word);
$ref_word = utf8_decode(urldecode("$ref_word"));
$ref_addr .= "$ref_word";
$_SESSION['ref'] = $ref_addr;
}
if(strpos($_SESSION['ref'], 'bing.com')){
$url_bing = $_SESSION['ref'];
$url_bing1 = parse_url($url_bing);
$query = array();
parse_str($url['query'], $query);
$ref_word = $query['q'];
$ref_addr = "Bing Search - ";
$ref_word = str_replace('+',' ',$ref_word);
$ref_word = utf8_decode(urldecode("$ref_word"));
$ref_addr .= "$ref_word";
$_SESSION['ref'] = $ref_addr;
}
echo "$_SESSION[ref]"; // When I searched with Bing: Bing Search - or with Seznam: Seznam Vyhledávač -
// It should be Bing Search - or Seznam Vyhledávač - value of 'q' variable from URL string