Home >Backend Development >PHP Tutorial >Implementation code for php regular judging url address and automatically converting it into hyperlink

Implementation code for php regular judging url address and automatically converting it into hyperlink

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:59:531236browse
Let me introduce you to a piece of PHP code that is used to determine the URL address and automatically convert it into a hyperlink. It uses a regular expression to match the URL in a string, and then converts the URL into a hyperlink and clicks to access the address. Friends in need can refer to it.

The code is as follows:

<?php
/**
 * php正则判断url 自动转换为超链接
 * site: bbs.it-home.org
*/
function autolink($foo)   
{   
    $foo = eregi_replace('(((f|ht)黑蕉tp://)[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '/1', $foo);   
    if( strpos($foo, "http") === FALSE ){   
    $foo = eregi_replace('(www.[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '/1', $foo);   
}else{   
    $foo = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_/+.~#?&//=]+)', '/1/2', $foo);   
}   
return $foo;   
}  
?>


Statement:
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
Previous article:PHP and HTTPSNext article:PHP and HTTPS