CodeIgniter Forums
Does anyone here know how to extract url on textarea using CI? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Does anyone here know how to extract url on textarea using CI? (/showthread.php?tid=42657)



Does anyone here know how to extract url on textarea using CI? - El Forum - 06-14-2011

[eluser]coderedmax[/eluser]
Like title said anyone here knows or have a function how to detect url on text area and convert it to anchor tag?

example :

user input this on textarea
Code:
I really love codeigniter visit http://codeigniter.com

then when need to input on database must be converted to
Code:
I really love codeigniter visit <a href="http://codeigniter.com" rel="nofollow">http://codeigniter.com</a>

like that! Anyone knows? thank you.


Does anyone here know how to extract url on textarea using CI? - El Forum - 06-14-2011

[eluser]bubbafoley[/eluser]
use auto_link() in the url helper

Code:
echo auto_link('I really love codeigniter visit http://codeigniter.com');

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html


Does anyone here know how to extract url on textarea using CI? - El Forum - 06-14-2011

[eluser]coderedmax[/eluser]
@bubbafoley

thanks! I didn't know CI have that features. :vampire:

anyway I got also alternative solution:
Code:
$content = $this->input->post('discussion_content', TRUE);
$find_url = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $content);

almost same but yours is easier. =) thanks again!