所以,假设我有just-a.domain.com,just-a-domain.info,just.a-domain.net如何删除扩展名.com,.net.info ...,我需要两个变量的结果,一个是域名,另一个是扩展名.
我试过str_replace但不起作用,我猜只有正则表达式....
我正在尝试编写(或只是找到一个现有的)PHP方法,它可以获取链接并提取URL.诀窍是,它需要保持在奇怪的领域的重压,如:
www.champa.kku.ac.th
Run Code Online (Sandbox Code Playgroud)
用人眼看着这个,我仍然猜错了:认为域名会是kku.ac.th但是访问时会出现dns错误.
所以任何人都知道从URL可靠地提取域的好方法:
http://site.com/hello.php
http://site.com.uk/hello.php
http://subdomain.site.com/hello.php
http://subdomain.site.com.uk/hello.php
http://www.champa.kku.ac.th/hello.php // and even the one I couldn't tell
Run Code Online (Sandbox Code Playgroud)