Home  >  Article  >  Backend Development  >  Link address program code in php matching characters_PHP tutorial

Link address program code in php matching characters_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:17:25726browse

Determine whether a string contains a hyperlink

The code is as follows
 代码如下  

$str="ssdsfsdfsdfss";
if(preg_match("/]*>|]*>/i",$str))
{
echo "该字符串有超链接";
}
else
{
echo "该字符串没有超链接标记";
}
?>

$str="ssdsfsdfsdfss";

if(preg_match("/]*>|]*>/i",$str))
{

echo "This string has a hyperlink";
 代码如下  

echo preg_replace("/(?<=href=)([^>]*)(?=>)/i","#", "你好,点这里看看你好,点这里看看");
?>

}

else

{

echo "The string has no hyperlink tag";
}
?>

Next we only need to filter the connection part.

The code is as follows
echo preg_replace("/(?<=href=)([^>]*)(?=>)/i","#", " Hello, click here to take a lookHello, click here to take a look"); ?>

Regular: /(?<=href=)([^>]*)(?=>)/
 代码如下  

function match_links($document) {   

    preg_match_all("']+))[^>]*>?(.*?)'isx",$document,$links);                       

    while(list($key,$val) = each($links[2])) {

        if(!empty($val))

            $match['link'][] = $val;

    }

    while(list($key,$val) = each($links[3])) {

        if(!empty($val))

            $match['link'][] = $val;

    }       

    while(list($key,$val) = each($links[4])) {

        if(!empty($val))

            $match['content'][] = $val;

    }

    while(list($key,$val) = each($links[0])) {

        if(!empty($val))

            $match['all'][] = $val;

    }               

    return $match;

}

(?<=exp) matches the position after exp

(?=exp) matches the position before exp

This regular match matches all characters