CodeIgniter – automatically make url and email as hyperlink

Hello Readers,

We might have seen plain text get converted to hypertext when we type it. For example, In gtalk when we type it automatically changes as a hyperlink and point to, Same way, when we type an email address it is automatically converted to

These kind of conversion can be made using PHP string replace function. We have to check the whole string where it has the url or email address, then we have to replace the url with anchor tag.

In CodeIgniter the easiest way to do it is to use the URL helper. First step is to load the URL helper.


Then the next thing to do is to use a function


This function makes our life easier. We have to pass the string that we need to find for url and email.

$string = "Today I visited a useful blog about web development and its url is";
echo auto_link($string);

The output of the above code is Today I visited a useful blog about web development and its url is

The same way email id is also auto linked. We can also restrict the automation only to url or email. This can be done by

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

In case if we want the link to open in a new tab, we can do it by adding a third parameter which can be either TRUE or FALSE.

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

Here second parameter ‘both’ indicates that both ’email’ and ‘url’ has to be automatically converted to hypertext.

Thanks for reading.

Follow me


Web Developer at Energy Alternatives India
I'm interested in developing Web applications andkeen on learning new technologies.

View Nagarajan's Profile
Follow me

Latest posts by Nagarajan (see all)

  1. bali wooden pavilions

Leave a Reply

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

займ на карту онлайн круглосуточно