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.anillabs.com"; |
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.
1 Comment
Stripz · January 9, 2013 at 8:25 am
Where is the code 2 be pasted?