Home > PHP > PHP Code > How to create auto hyperlinks using 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.

You may also like
Website uptime monitoring using PHP script
Understanding the basic need of MVC architecture
How to convert feeds to html using javascript and php
Multi-language support for web application with MySql and PHP

1 Response

Leave a Reply

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