PHP Code

How to create auto hyperlinks using PHP code

The following script will help you to create auto hyperlinks using php code.

our string :

$string = " this is blog of anil kumar panigrahi http://www.anillabs.com";

call the function like

addLink($string);
How to create auto hyperlinks using PHP code by Anil Kumar Panigrahi
How to create auto hyperlinks using PHP code by Anil Kumar Panigrahi

below code will be split into sting + hyperlink url.

function addLink($string){
$breakstring = explode(" ", $string);
for ($i=0; $i<=sizeof($breakstring)-1; $i++)
{
if ((substr($breakstring[$i], 0, 7) == 'http://') &&$breakstring[$i] != 'http://'))
$string = str_replace($breakstring[$i], "<a href="'.$breakstring[$i].'">".$breakstring[$i]."</a>", $string);
}
return $string;
}

Hope that it will be useful.

1 thought on “How to create auto hyperlinks using PHP code”

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.