首先从URL获取子域很容易.
http://www.domain.example
Run Code Online (Sandbox Code Playgroud)
扫描第一个时间段然后返回"http://"之后的任何内容......
然后你记得
http://super.duper.domain.example
Run Code Online (Sandbox Code Playgroud)
哦.所以,你想,好吧,找到最后一个时期,回过头来获取一切!
然后你记得
http://super.duper.domain.co.uk
Run Code Online (Sandbox Code Playgroud)
而你又回到了原点.除了存储所有顶级域名列表外,任何人都有任何好主意吗?
我有完整的URL作为字符串,但我想删除字符串开头的http://以很好地显示URL(例如:www.google.com而不是http://www.google.com)
有人可以帮忙吗?
function url(){
if(isset($_SERVER['HTTPS'])){
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
}
else{
$protocol = 'http';
}
return $protocol . "://" . $_SERVER['HTTP_HOST'];
}
Run Code Online (Sandbox Code Playgroud)
例如,使用上面的函数,如果我使用相同的目录,它工作正常,但如果我创建一个子目录,并在其中工作,它也将给我子目录的位置,例如.我只是想要,example.com
但它给了我,example.com/sub
如果我在文件夹中工作sub
.如果我正在使用主目录,该功能正常.有替代品$_SERVER['HTTP_HOST']
吗?
或者我怎么能修复我的功能/代码才能获得主网址?谢谢.
我需要一个php函数,它从URL生成一个纯域名.因此http://
,如果这些部分存在,则必须删除此函数,www
并/
从URL中删除(斜杠)部分.以下是输入和输出示例:输入 - > http://www.google.com/ | 输出 - > google.com
输入 - > http://google.com/ | 输出 - > google.com
输入 - > www.google.com/ | 输出 - > google.com
输入 - > google.com/ | 输出 - > google.com
输入 - > google.com | 输出 - > google.com
我检查了parse_url
功能,但没有返回我需要的内容.因为,我是PHP的初学者,对我来说很难.如果您有任何想法,请回答.
Thanx提前.
说有人输入这样的URL:
http://i.imgur.com/a/b/c?query=value&query2=value
Run Code Online (Sandbox Code Playgroud)
我想回来: imgur.com
不 i.imgur.com
这是我现在的代码
$sourceUrl = parse_url($url);
$sourceUrl = $sourceUrl['host'];
Run Code Online (Sandbox Code Playgroud)
但这会回来 i.imgur.com
给定URL,如何使用公共后缀列表(有效TLD 列表,例如此列表)提取注册域名?
例如,考虑a.bg
是有效的公共后缀:
http://www.test.start.a.bg/hello.html -> start.a.bg
http://test.start.a.bg/ -> start.a.bg
http://test.start.abc.bg/ -> abc.bg (.bg is the public suffix)
Run Code Online (Sandbox Code Playgroud)
这不能使用简单的字符串操作来完成,因为公共后缀可以由多个级别组成,具体取决于TLD.
PS我如何读取列表(数据库或平面文件)并不重要,但列表应该可以在本地访问,所以我并不总是依赖于外部服务.
我需要从字符串中提取域名,这可能是任何东西.如:
$sitelink="http://www.somewebsite.com/product/3749875/info/overview.html";
Run Code Online (Sandbox Code Playgroud)
要么
$sitelink="http://subdomain.somewebsite.com/blah/blah/whatever.php";
Run Code Online (Sandbox Code Playgroud)
在任何情况下,我都想提取'somewebsite.com'部分(可能是任何东西),并丢弃其余部分.
我有以下php变量
$currentUrl
Run Code Online (Sandbox Code Playgroud)
这个php变量返回当前的url页面.例如:它返回:
http://example.com/test-category/page.html?_ore=norn&___frore=norian
Run Code Online (Sandbox Code Playgroud)
我可以使用哪些PHP代码将获取此URL链接并删除" .html " 之后的所有内容,并将返回一个干净的URL链接,例如:
http://example.com/test-category/page.html
Run Code Online (Sandbox Code Playgroud)
这将在新变量$ clean_currentUrl中返回
我有2个表(url_feed
和clean_domains
).我正在尝试将所有数据复制url_feed
到clean_domains
同一时间并domain
从url
列中插入.
此外,它会在将行复制到之后将status
from 更改queued
为complete
in .url_feed
clean_domains
这是2个表的样子:
url_feed
id | url | matches | networks | status
1 | http://whatever.com/example1.php | 5 | Facebook::Twitter Inc | queued
2 | http://www.example.com/other-stuff.php | 2 | MySpace::Facebook::Twitter | queued
3 | http://www.test.com/random-text | 12 | Instagram::Twitter | queued
Run Code Online (Sandbox Code Playgroud)
clean_domains
id | domain | url | matches | networks | status
1 | whatever.com | http://whatever.com/example1.php …
Run Code Online (Sandbox Code Playgroud) 如果我有一个包含URL的变量,那么我该如何获得基本URL?那是,
$url = 'http://www.domain.com/some/stuff/that/I/do/not/want/';
$base_url = some_clever_function($url);
// $base_url is now set equal to 'domain.com'
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个像这样的简单脚本
$data = "http://example.com/index.php?data=data&value=value";
Run Code Online (Sandbox Code Playgroud)
如何从$ data获取基本URL?输出将是这样的
http://example.com
Run Code Online (Sandbox Code Playgroud)
没有此文本的输出"/index.php?data=data&value=value
可能重复:
在PHP中从URL解析域
如何得到
http://localhost/
Run Code Online (Sandbox Code Playgroud)
从
http://localhost/something/
Run Code Online (Sandbox Code Playgroud)
用php
我试过了
$base = strtok($url, '/');
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个whois检查脚本.
用户可以提交一些域名地址,然后在可用或不可用时收到消息.
$_POST['url']
是用户提交的值.
我怎么知道这个变量是否是域名地址?
它应该为true
以下领域提供:
http://google.com
www.google.com
http://www.google.com
google.com
Run Code Online (Sandbox Code Playgroud)
对于javascript也一样(我也使用ajax验证)?