时间:2021-07-01 10:21:17 帮助过:3人阅读
输出:
又如PHP函数parse_url使用方法:
- < ?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
- )
可以看到,PHP函数parse_url可以很容易分解出一个URL的各个部,那如果要拿指定的部分出来的话也很容易,如
echo parse_url($url, PHP_URL_PATH);就是在第二个参数中,设定如下的参数:
PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT.
http://www.bkjia.com/PHPjc/445957.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445957.htmlTechArticle$ url = http://www.electrictoolbox. com/php-extract-domain-from-full-url/ ; $ parts = parse_url ($url); 输出: Array ( [scheme]= http [host]= www.electrictoolbox.com [path]= /php-...