Link address program code in php matching characters_PHP tutorial

WBOY
Release: 2016-07-20 11:17:25
Original
728 people have browsed it

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
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template