2011-01-29 49 views
1
index.php?option=com_virtuemart&Itemid=210&category_id=12&lang=is&limit=20&limitstart=180&page=shop.browse 

检索参数,我想检索字符串中的参数,而且如果页面参数等于“shop.browse”比返回真布尔值。从字符串

编辑:ps。该字符串并不总是看起来像这样,但它始终包含页面参数

我一直在搞strpos函数和其他人,我无法得到这个工作,我需要这个代码很快,所以如果任何人都可以指向我有最佳方​​法的正确方向。

谢谢

+0

你得到的URL为GET?或者这是一个URL保存在一个字符串? – kjy112 2011-01-29 15:03:53

回答

5

使用parse_url首先得到公正的查询部分,然后用parse_str得到的值:

$query = parse_url($str,PHP_URL_QUERY); 
parse_str($query, $match); 
if ($match['page'] === 'shop.browse') { 
    // page=shop.browse 
} 

注意,这里假设你的字符串存储在一个变量$str

+1

+1,以获得问题的完整解决方案。 – 2011-01-29 15:07:59

1

检查parse_url()函数。

0

整个事情:

<?php 

$url = "index.php?option=com_virtuemart&Itemid=210&category_id=12&lang=is&limit=20&limitstart=180&page=shop.browse"; 
$url = parse_url($url); 
parse_str($url['query'], $output); 
if($output['page'] == "shop.browse") 
{ 
    //stmts 
} 
else 
{ 
    //stmts 
} 
0

$ str = explode(“?”,$ url);

$ str = explode(“&”,$ str [1]);

的foreach($ str作为$ K => $ v)的{

$ XXX =爆炸( “=”,$ V);

$ output [$ xxx [0]] = $ output [$ xxx [1]];

}

echo $ output [“page”];

这样你就可以得到所有映射到它们键值的参数。你会得到类似$ _GET/$ _ POST东西的东西。