Home Backend Development PHP Tutorial 哪位高手能帮忙写一个正则表达式

哪位高手能帮忙写一个正则表达式

Jun 13, 2016 pm 01:46 PM
http quot str url

谁能帮忙写一个正则表达式
url替换为超连接

比如:
呵呵http://www.sina.com.cn西西哈哈    
替换之后是:
呵呵 http://www.sina.com.cn 西西哈哈

在比如:
中国最大的技术论坛:www.csdn.net,你可以学到很多东西
替换之后是:
中国最大的技术论坛: www.csdn.net ,你可以学到很多东西

总之,是URL都要替换为超连接.高手帮忙写一下.谢谢

------解决方案--------------------


function enable_url($str)
{
$str = ereg_replace( "([url]www.[a-zA-Z0-9@:%_.~#-\?&]+[/url]) ", " \\1 ", $str); // 自动转化www开头的链接
$str = ereg_replace( "(((f|ht){1}tp://)[a-zA-Z0-9@:%_.~#-\?&]+) ", " \\1 ", $str); //转化[url]http://开头和ftp://开头的链接[/url]
$str = str_replace( 'linkHttp:// ', 'http:// ',$str);
$str = ereg_replace( "([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}) ", " \\1 ", $str); // 转化邮件地址
return $str;
}
//for example
echo enable_url( "呵呵http://www.sina.com.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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

What does http status code 520 mean?

Why NameResolutionError(self.host, self, e) from e and how to solve it Why NameResolutionError(self.host, self, e) from e and how to solve it Mar 01, 2024 pm 01:20 PM

Why NameResolutionError(self.host, self, e) from e and how to solve it

How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS Sep 26, 2023 am 11:19 AM

How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand common application scenarios of web page redirection and understand the HTTP 301 status code

http request 415 error solution http request 415 error solution Nov 14, 2023 am 10:49 AM

http request 415 error solution

What is http status code 403? What is http status code 403? Oct 07, 2023 pm 02:04 PM

What is http status code 403?

Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files Sep 12, 2023 pm 01:15 PM

Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files

What is the difference between html and url What is the difference between html and url Mar 06, 2024 pm 03:06 PM

What is the difference between html and url

See all articles