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] : '';
}

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/125881089