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

WBOY
Release: 2016-07-25 08:59:53
Original
1195 people have browsed it
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;   
}  
?>
Copy after login


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