doubingguan3425 2011-03-08 02:59
浏览 60
已采纳

如何从url获取Domain.ext? PHP prase

if we have

 $url = "http://subdomain.domin.ext/somepath/file.php";

how to get the domain.ext

when I used

 $parse = parse_url($url);
 $domin = $parse[host];

then echo "$domain"; //this returns subdomain.domin.ext

is there any idea to get domain.ext?

  • 写回答

3条回答 默认 最新

  • douhunbei0166 2011-03-08 03:12
    关注
    $url = "http://subdomain.domin.ext/somepath/file.php";
    $parse = parse_url($url);
    $domain = $parse['host'];
    $lastDot = strrpos($domain,'.');
    $ext = substr($domain,$lastDot+1);
    

    This will get you "ext" (e.g. "com" or "gov"). In the case of something like amazon.co.uk, it will give you "uk". If you need "co.uk", you will need to add logic to detect certain TLDs (e.g. "uk") and go to the second dot on those cases.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 steam下载游戏占用内存
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系