function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
开发者_如何学C $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret);
return $ret;
}
I'm trying to get this function to autolink my links on my blog,
<?php autolink(@solomonaleh); ?>
But I get a blank screen. Thank you.
You also need to echo it since it returns a string.
<?php echo autolink('@solomonaleh'); ?>
You need to quote your argument:
<?php autolink('@solomonaleh'); ?>
Otherwise the @
is a syntax error. You may also need to actually call the name of the function you define - your function code defines a function named 'twitterify', but you call one named 'autolink' - which is it?
sorry guys i have the solution, its my mistake, the function deos work, its just that you have to echo the arguement to SEE it Stupid Me!!
$tweet = "hey, @twitter what are you doing";
echo autolink($tweet);
thanks people!!!
精彩评论