How to create auto hyperlinks using PHP code

in PHP Code / 1 Comment

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.anil2u.info";

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.

With more than 8 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : php.anil@gmail.com

Discussion 1 Comment

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>