当前位置:编程学习 > php >>

php 匹配正则 取出url

php 匹配正则 取出url

取出所有url 并且不要重复

function getJustAllUrl($inUrlText)
{
    $parttern = "/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/";
    preg_match_all($parttern, $inUrlText, $match);
 
    return count($match) > 0 ? array_unique($match[0]) : '';

}


取出仅仅url

function getJustUrl($inUrlText)
{
    $parttern = "/http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/";
    preg_match($parttern, $inUrlText, $match);
    return count($match) > 0 ? $match[0] : '';
}

 

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,