从URL字符串

时间:2016-03-25 15:22:07

标签: php explode

我需要最佳解决方案才能从网址获取“令牌”。

网址示例(始终采用相同的结构):

https://steamcommunity.com/tradeoffer/new/?partner=123456789&token=qwerty1@

我希望只能从此网址获取 qwerty1@

哪种选择最好,最安全,而且速度更快?

问候。

2 个答案:

答案 0 :(得分:2)

您可以使用parse_url获取查询字符串,然后使用parse_str获取token

parse_str(parse_url(
   'https://steamcommunity.com/tradeoffer/new/?partner=123456789&token=qwerty1@',
   PHP_URL_QUERY
), $result);

echo $result['token']; // qwerty1@

答案 1 :(得分:0)

怎么样?

$arr = explode("=", $string);
echo end($arr); //prints "qwerty1@"