
从 url 中提取指定部分
需要从以下 url 中提取 "?referer=" 和 "&username=" 之间的内容:
web.admin.com/admin/usermanage/investuser?start=2018-01-02%2000:00:00&end=2018-01-02%2010:41:46&itype=3&isfirst=3&referer=http://testhf.irongbei.com/muserregister/register2?v=10f454&key=311bcdec754052e40fe025a54f488f9a&rbref=rbzc&isshow=&username=&pname=&plattype=0&istatus=1&buy_type=0&channel_source=62
url 编码错误,无法直接提取所需的内容。需要将其进行 url 解码处理。
$encodedUrl = 'web.admin.com/admin/userManage/investuser?start=2018-01-02%2000:00:00&end=2018-01-02%2010:41:46&itype=3&isfirst=3&referer=http://testhf.irongbei.com/MUserRegister/register2?v=10f454&key=311bcdec754052e40fe025a54f488f9a&rbref=rbzc&isShow=&username=&pname=&plattype=0&istatus=1&buy_type=0&channel_source=62';
$decodedUrl = urldecode($encodedUrl);
preg_match('/referer=(.*?)&username/', $decodedUrl, $matches);
if (isset($matches[1])) {
$result = $matches[1];
} else {
$result = null;
}
echo $result; //输出 "http://testhf.irongbei.com/MUserRegister/register2?v=10f454&key=311bcdec754052e40fe025a54f488f9a&rbref=rbzc"









