View Single Post
Old February 9th, 2009, 4:51 PM   #4 (permalink)
MarkRH
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,510 posts
Gave thanks: 21
Thanked 104 times
Okay, here's what I got based on that code.. the only thing it misses is a username that is at the end of a string.

PHP Code:
<?php
function twitterify($tweet) {
    
//CONVERT *://.* TO LINK (EG HTTP://KEVINSMITHDESIGNS.COM)
    
$tweet ereg_replace("[a-zA-Z]+://([.]?[a-zA-Z0-9_/-])*"'<a href="\\0" target="_blank">\\0</a>'$tweet);
    
//CONVERT *://*.* TO LINK (EG HTTP://WWW.KEVINSMITHDESIGNS.COM)
    
$tweet ereg_replace("(^| )(www([.]?[a-zA-Z0-9_/-])*)"'<a href="\\1\\2" target="_blank">\\1\\2</a>'$tweet);
    
//LINK @USERNAME
    
$tweet preg_replace('/([\.|\,|\:|\¡|\¿|\>|\{|\(]?)@{1}(\w*)([\.|\,|\:|\!|\?|\>|\}|\)]?)\s/i''$1@<a href="http://twitter.com/$2" target="_blank">$2</a>$3 '$tweet);
    return 
$tweet;
}

$tweet "@mrheadrick Hey @mozunk! Go check out http://digsby.com -- http://www.markheadrick.com I think you will like it. @robmonroe";
echo 
twitterify($tweet).'<br>';
// add extra space this time
$tweet .= ' ';
echo 
twitterify($tweet);
// get rid of space now
$tweet rtrim($tweet);

?>
I needed to add a space to the end of the string for it to catch username that comes at the end of the string. They way they had it coded, it was replacing what it found with itself so it didn't actually change anything LOL.
__________________
SH102 : Mark Headrick - Blog - Gallery
Pelicar | Company of Valor | Mysstie
MarkRH is offline   Reply With Quote