【发布时间】:2014-02-03 18:46:38
【问题描述】:
我有一个函数,我想从字符串中删除部分字符串。
我想删除以下子字符串http://ftp://www.www2.,这些子字符串可能放在域名前面。
这是代码,但它不起作用,我可能遗漏了一些非常明显的东西。
private function GetValidDomainName($domain)
{
if(strpos($domain, 'http://'))
{
$this->domain = str_replace("http://", "", $domain);
}
if(strpos($domain, 'ftp://'))
{
$this->domain = str_replace("ftp://", "", $domain);
}
if(strpos($domain, 'www.'))
{
$this->domain = str_replace("www.", "", $domain);
}
if(strpos($domain, 'www2.'))
{
$this->domain = str_replace("www2.", "", $domain);
}
$dot = strpos($domain, '.');
$this->domain = substr($domain, 0, $dot);
$this->tld = substr($domain, $dot+1);
}
这是我在域名可用性的 WHOIS 检查中使用的第一个功能,我有一个功能可以在以后检查可用字符并允许域名长度等,它们都可以正常工作,并且检查本身工作得很好,但只是这个函数没有做它应该做的事情。
【问题讨论】:
标签: php regex string str-replace