ESHAN
Please Help Any Helpless Person
23 February, 2010
Replace Links With Html
You can replace links with html tag using PHP regular expression.
Here is an example of it.
function replace_link_with_link($string)
{
$pattern = "|http://(\w+)([A-Z0-9-_:./?]+)*|i";
$string = preg_replace($pattern,'<a href="\0">\0</a>',$string);
return $string;
}
Enjoy. Help Helpless.
Regular Expression To Replace All Mentioned Name With Link
In twitter
Rana vai
gave me a code to replace all mentioned name with link like twitter.
Check that
.
There was 2 problem.
I anyone use '.' after mentioned name then there will be '.' in link.
There will be '@' in link.
Here is a function. I hope it will work perfectly
function link_from_at($string)
{
$status = preg_replace("|@([a-zA-Z0-9]+)*|",'@<a href="\1">\1</a>',$string);
return $status;
}
22 February, 2010
Regular Expression to Find All Mentioned Names by ‘@’
I have seen a cool example about it at
Junal vai's blog
. Here is a shortcut example of it..
function name_from_at($string)
{
$pattern = "/@([a-zA-Z0-9]+)/i";
preg_match_all($pattern,$string,$array);
return $array[0];
}
Enjoy..... Help the people of Haiti......
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)