CodeIgniter – Make URLs and Emails as Hyperlinks Automatically

Read Time1 Minute, 29 Seconds

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.

$this->load->helper('url');

Then you can use the below function.

auto_link();

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

$string = "KDJ Guru (www.kdjguru.com) is the best blog in Sri Lanka. please contact us through info@kdjguru.com";
echo auto_link($string);

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

echo auto_link($string,'email');
echo auto_link($string,'url');

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

echo auto_link($string, 'both', TRUE);

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!

 

1 0

About Post Author

Kavidu Jayakody

Kavidu Dilshan Jayakody is the founder and the author of KDJ Blog. He is a skilled web developer and graphic designer. In addition, he has earned his degree BSc (Hons) Computing, UK. He is working as a tutor of an institute and as a part-time blogger, he will help you all to make your problems solved.
0 %
Happy
0 %
Sad
0 %
Excited
0 %
Angry
0 %
Surprise

Leave a Comment

Your email address will not be published. Required fields are marked *

KDJ Singlish 1.1.0 for PC/Android/Google Chrome
Download Now

Scroll to Top