oaziz
oaziz

Reputation: 1372

Yii: How can I linkify all URLs in some text?

Say I have a forum thread and I want to make all mentioned URLs as clickable links. How can I accomplish this in Yii?

Thanks.

Upvotes: 0

Views: 344

Answers (2)

ldg
ldg

Reputation: 9402

Did you look into CHtmlPurifier? see: Linkify and http://htmlpurifier.org/demo.php

Upvotes: 2

Jeff Lambert
Jeff Lambert

Reputation: 24661

This is copied straight from this stackoverflow question

$text = preg_replace("
  #((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#ie",
  "'<a href=\"$1\" target=\"_blank\">$3</a>$4'",
  $text
);

Upvotes: 3

Related Questions