正则如何得到域名中间字符串? 本帖最后由 mingfish2 于 2011-02-21 11:56:07 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以下代码验证通过<?php$href="http://site.com"; $href="http://site.com.cn"; $href="http://site.net.cn"; $href="http://www.site.com"; $href="http://blog.site.com"; $href="http://blog.site.com/index.html"; $href="http://blog.site.com.cn/index.html"; $href="http://xxx.site.xx.xx/xxx.html"; $whois = array('com','net','cc','cn','org','info','com.cn','net.cn',);if(preg_match('/http:\/\/(\w+)\.(\w+)/i',$href,$match)){ if($match[1]!='www' && in_array($match[2],$whois)){ $out = $match[1] ; }elseif($match[1]!='www' && !in_array($match[2],$whois)){ $out = $match[2] ; }else{ $out = $match[2]; } }echo '<pre>';print_r($out);?> 这个更准确[code=PHPp]$href="http://site.com"; //$href="http://site.com.cn"; //$href="http://site.net.cn"; //$href="http://www.site.com"; //$href="http://blog.site.com"; //$href="http://blog.site.com/index.html"; //$href="http://blog.site.com.cn/index.html"; //$href="http://xxx.site.xx.xx/xxx.html"; $whois = array('com','net','cc','cn','org','info','com.cn','net.cn',);if(preg_match('/http:\/\/(\w+)\.(\w+)/i',$href,$match)){//print_r($match); if(in_array($match[2],$whois)){ $out = $match[1] ; }else{ $out = $match[2]; } }echo $out ;[/code] 字符过滤 为什么什么也没有显示? 如图,如何取指定时间段里面的数据? 谁有这个Flash插件,谢谢 问个 smarty section 用法 如何在<tr>中提交表单 怎样用adodb这套组件不用limit 10,40之类的sql语句来达到分页的目的?以及,如何象在asp里面调用ado这种com对象的时候设置CursorType和Lo 一个对于我这个初学PHP者奇怪的问题! 谢谢!! hhvm 无法正常工作,请问如何安装hhvm_fastcgi请指点。。。 php DOMDocument()::load()函数问题 怎么做,才能搜索出两个MYSQL数据库的内容
<?php
$href="http://site.com";
$href="http://site.com.cn";
$href="http://site.net.cn";
$href="http://www.site.com";
$href="http://blog.site.com";
$href="http://blog.site.com/index.html";
$href="http://blog.site.com.cn/index.html";
$href="http://xxx.site.xx.xx/xxx.html";
$whois = array('com','net','cc','cn','org','info','com.cn','net.cn',);
if(preg_match('/http:\/\/(\w+)\.(\w+)/i',$href,$match)){
if($match[1]!='www' && in_array($match[2],$whois)){
$out = $match[1] ;
}elseif($match[1]!='www' && !in_array($match[2],$whois)){
$out = $match[2] ;
}else{
$out = $match[2];
}
}
echo '<pre>';
print_r($out);
?>
[code=PHPp]$href="http://site.com";
//$href="http://site.com.cn";
//$href="http://site.net.cn";
//$href="http://www.site.com";
//$href="http://blog.site.com";
//$href="http://blog.site.com/index.html";
//$href="http://blog.site.com.cn/index.html";
//$href="http://xxx.site.xx.xx/xxx.html";
$whois = array('com','net','cc','cn','org','info','com.cn','net.cn',);
if(preg_match('/http:\/\/(\w+)\.(\w+)/i',$href,$match)){
//print_r($match);
if(in_array($match[2],$whois)){
$out = $match[1] ;
}else{
$out = $match[2];
}
}
echo $out ;[/code]