我想从以下网址字符串中找到变量:
这是我的字符串:
$var = "http://localhost/trans/site/index#ads=10"
如何从该字符串中获得$ads
?
答案 0 :(得分:4)
<?php
$var = "http://localhost/trans/site/index#ads=10";
echo $ads = parse_url($var, PHP_URL_FRAGMENT);
?>
输出:ads = 10
<?php
$var = "http://localhost/trans/site/index#ads=10";
$ads = parse_url($var, PHP_URL_FRAGMENT);
echo $ten = (explode("=",$ads)[1]);
?>
输出:10