php:如何从网址字符串中找到变量的结果

时间:2018-12-29 10:28:05

标签: php

我想从以下网址字符串中找到变量:

这是我的字符串:

$var = "http://localhost/trans/site/index#ads=10"

如何从该字符串中获得$ads

1 个答案:

答案 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