Home  >  Article  >  Backend Development  >  如何用正则截取域名中间的部分

如何用正则截取域名中间的部分

WBOY
WBOYOriginal
2016-06-13 13:27:011267browse

怎么用正则截取域名中间的部分
比如 www.baidu.com abc.baidu.com www.baidu.com.cn 后缀有很多种 要求能都截取中间的 baidu

------解决方案--------------------

PHP code
$s = 'www.baidu.com abc.baidu.com www.baidu.com.cn';
preg_match_all('/(\w+)\.com/i', $s, $r);
print_r($r); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn