Hello everyone, welcome back to KDJ Guru. This article is for our Codeigniter developers who are trying to make URLs automatically as hyperlinks. It’s cool ah. Yes, it is. If we can do that, it will save the time of all the developers. Let’s see what will be happened when we use this trick.

As you already know, to make URL as a hyperlink, you have to use anchor tags with the link on href attribute. anyway, it’s not easy when we can’t identify whether all of them are links or not. However, if you are a PHP developer (Pure), you can write something to make it happen. If you are a developer who uses the Codeigniter framework, it would be easy by wrapping the whole text with a small function.

First, you must load the URL helper from autload.php or directly in the controller.

[code]$this->load->helper(‘url’);[/code]

Then you can use the below function.

[code]auto_link();[/code]

That’s all. However, you use the above function like this.

[code]$string = “KDJ Guru (www.kdjguru.com) is the best blog in Sri Lanka. please contact us through info@kdjguru.com”;
echo auto_link($string);[/code]

If you need to restrict, (URL & Email), you can use the below function. Just add what you need to make hyperlinks.

[code]echo auto_link($string,’email’);
echo auto_link($string,’url’);[/code]

In case if you need a separate tab to open those links, you can use it as below. “both” means, email and URLs.

[code]echo auto_link($string, ‘both’, TRUE);[/code]

That’s all that I can teach from this tut. If you like this article, please take some time to share with your friends. I will write another one soon. Good Bye!

 

Write A Comment