如果$ url ='http://yalumalu.com/watch_video.php?v =UXNWH2YA43RU';是我的网址,
如何在参数“V =”中获取值?
我尝试使用explode url但它返回一个空值?我... ...
答案 0 :(得分:1)
编辑考虑@Brad建议
$pos = strpos($url,'?') + 1;
parse_str(substr($url,$pos),$arg);
echo $arg['v'];
答案 1 :(得分:0)
您是否尝试过parse_url:
http://php.net/manual/en/function.parse-url.php
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';
print_r(parse_url($url));
echo parse_url($url, PHP_URL_PATH);
?>
应该给予
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)
/path
所以你想要的东西是:
$parsedUrl = parse_url($url);
var_dump($parsedUrl['query']);
$result = explode('=', $parsedUrl['query']);
$v = $result[1];
var_dump($v);
哪个应输出
UXNWH2YA43RU