Home » PHP Code »

0

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

our string :

1
$string = " this is blog of anil kumar panigrahi http://www.anil2u.info";

call the function like

1
addLink($string);

below code will be split into sting + hyperlink url.

1
2
3
4
5
6
7
8
9
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.


Related Posts

    How to remove consecutive whitespaces using php?How to display the mysql table schema using php code?How to Build PHP application in Google App EngineWhat is cron job ? How to set the cron job in PHP?

 

Leave a Reply