如何从php中的URL去除域名? [英] How do you strip out the domain name from a URL in php?

查看:2003
本文介绍了如何从php中的URL去除域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法(或函数),以去除馈入该函数的所有URL的domain.ext部分.域扩展名可以是任何内容(.com,.co.uk,.nl,.whatever),并且馈入其中的URL可以是 http://www.domain.com 到www.domain.com/path/script.php?=任何

Im looking for a method (or function) to strip out the domain.ext part of any URL thats fed into the function. The domain extension can be anything (.com, .co.uk, .nl, .whatever), and the URL thats fed into it can be anything from http://www.domain.com to www.domain.com/path/script.php?=whatever

执行此操作的最佳方法是什么?

Whats the best way to go about doing this?

推荐答案

parse_url 将URL转换为关联数组:

parse_url turns a URL into an associative array:

php > $foo = "http://www.example.com/foo/bar?hat=bowler&accessory=cane";
php > $blah = parse_url($foo);
php > print_r($blah);
Array
(
    [scheme] => http
    [host] => www.example.com
    [path] => /foo/bar
    [query] => hat=bowler&accessory=cane
)

这篇关于如何从php中的URL去除域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆