已知字符串

https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN

从上面这段url字符串中,提取出 qq.com 或者 weixin.qq.com

function checkUrls($domain)
{
    $domain = '`https://open.weixin.qq.com/cgi-bin/frame?t=home/app_tmpl&lang=zh_CN`';
    $httpurl = strtolower(trim($domain));
    if (empty($httpurl)) return;
    $regx1 = '/https?:\/\/(([^\/\?#]+\.)?([^\/\?#-\.]+\.)(com\.cn|org\.cn|net\.cn|com\.jp|co\.jp|com\.kr|com\.tw)(\:[0-9]+)?)/i';
    $regx2 = '/https?:\/\/(([^\/\?#]+\.)?([^\/\?#-\.]+\.)(cn|com|org|net|cc|biz|hk|jp|kr|name|me|tw|la)(\:[0-9]+)?)/i';
    $host = '';
    if (preg_match($regx1, $httpurl, $matches)) {
        $host = $matches[3] . $matches[4];
    } elseif (preg_match($regx2, $httpurl, $matches)) {
        $host = $matches[3] . $matches[4];
    }
    return $host
}
最后修改于:2021-09-16 01:16
文章链接: https://oct.cn/view/38
版权声明: 本站所有文章除特别声明外。转载请注明来自 十月笔记