PHP如何分割URL [英] php how to split url

查看:246
本文介绍了PHP如何分割URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何分割此网址?

http://www.example. com/news?q = string& f = true& id = 1233& sort = true

我只需要示例

推荐答案

使用如下的parse_url:

Use parse_url like below:

<?php
$url = 'http://www.example.com/news?q=string&f=true&id=1233&sort=true';

$values = parse_url($url);

$host = explode('.',$values['host']);

echo $host[1];

?>

这将适用于包含子域的所有网址(例如www.etc)

This would work for any url that has the sub domain included (www. etc)

可以在以下位置找到PHP文档: http://php.net/manual/zh-CN/function.parse-url.php

The PHP documentation can be found here: http://php.net/manual/en/function.parse-url.php

这篇关于PHP如何分割URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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