2012-01-25 38 views
0

我想在Codeigniter中設置一個函數來將URL變成活動鏈接。我發現here以下的函數 - 通常用於PHP,但需要與Codeigniter類似的函數。希望在整個我的網站中使用它來發布用戶信息和評論。如何鏈接Codeigniter中的URL?

$text = preg_replace('/(?<!http:\/\/)(www.[[email protected]:%_\+.~#?&\/=]+)/i', '<a href="http://\1">\1</a>', $text); 

回答

1

我結束了使用auto_link(),這是

0

只需將preg_replace命令放入您的網頁中即可: $ text =「訪問網頁http://masalahkita.com以查看此作品,Web使用CodeIgniter框架並以此方式應用。 $ link = preg_replace(「/([\ w] +:// [\ w-?&;#〜=。/ \ @] + [\ w /])/ i」,「$ 1」,$ text) ; echo $ link;

0

考慮CI中的URL Helper。有幾個功能可以協助處理URL。請專門查看anchor()函數。在您的控制器

function linkify($text){ 
    return preg_replace('/(?<!http:\/\/)(www.[[email protected]:%_\+.~#?&\/=]+)/i', '<a href="http://\1">\1</a>', $text); 
} 

現在:

//$content = 'get your content from somewhere' 
$this->load->helper('text'); 
$content = linkify($content); 
0

application/helpers

創建一個名爲MY_text_helper.php文件擺在那裏了以下功能一個嵌入codeigniter的函數。因此,如果有人發佈消息,並且想要鏈接任何網址,只需使用:

auto_link($message) 

我發現它埋在codeigniter文檔中。