當前位置:編程學習大全網 - 網站源碼 - 我用php做的壹個發言性質的模塊,怎麽讓輸入網址的時候自動加入鏈接

我用php做的壹個發言性質的模塊,怎麽讓輸入網址的時候自動加入鏈接

mvc01,妳好:

妳所提出的問題使用正則即可解決,具體如下:

自動添加"http://"頭的PHP函數代碼:

<?php

if?(!preg_match("/^(http|ftp):/",?$_POST['url'])){

$_POST['url']?=?'

$_POST['url'];

}

>

PHP將網址字符串轉換成超級鏈接,可將URL和E-mail 地址字符串轉換為可點擊的超級鏈接:

<?php

function?makeClickableLinks($text)?{

$text?=?eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_+.~#?&//=]+)',

'<a?href="\1">\1</a>',?$text);

$text?=?eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_+.~#?&//=]+)',

'\1<a?href="

,?$text);

$text?=?eregi_replace('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,3})',

'<a?href="mailto:\1">\1</a>',?$text);

return?$text;

}

>

  • 上一篇:野馬效應是什麽呢?
  • 下一篇:Spring Boot教程第22篇:整合elk,搭建實時日誌平臺
  • copyright 2024編程學習大全網