Home > php教程 > php手册 > body text

php判断url地址并转换为超链接

WBOY
Release: 2016-06-06 19:50:54
Original
1462 people have browsed it

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 用php判断url地址并自动转换为超链接,在一段字符串中用正则表达式匹配出url,在将url转换为超链接,点击可访问地址: function autolink($foo) { $foo = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    用php判断url地址并自动转换为超链接,在一段字符串中用正则表达式匹配出url,在将url转换为超链接,点击可访问地址:

    function autolink($foo)

    {

    $foo = eregi_replace('(((f|ht){1}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;

    }

php判断url地址并转换为超链接

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template