icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old February 9th, 2009, 5:51 AM   #1 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
Twitter @replies

I am looking for a PHP function that can convert replies in a string to a link leading to their profile.

I have already found a function to convert plain text to URLs when "http://" or "www." is present, but I can't find a working one for replies. I found one that didn't seem to do anything at all, and I think I'm just not using the right keywords.

Basically I want "robmonroe" to be converted to:
Code:
@<a href="http://twitter.com/robmonroe">robmonroe</a>
If you know how, or have a link to a snippet, that'd be awesome.
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 7:10 AM   #2 (permalink)
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
If you haven't found something by the time I get up tomorrow, I'll take a crack at it.
__________________
SH102 : Mark Headrick - Blog - Gallery
Pelicar | Company of Valor | Mysstie
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 5:13 PM   #3 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
Kevin Smith PHP: Autolink Text - Twitter replies

This was the one that I found. But it doesn't work.
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 5:51 PM   #4 (permalink)
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  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 6:03 PM   #5 (permalink)
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
Well, this would probably work better to just pass the string with the extra space attached, since this doesn't modify the original value in $tweet
PHP Code:
echo twitterify($tweet.' '); 
__________________
SH102 : Mark Headrick - Blog - Gallery
Pelicar | Company of Valor | Mysstie
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 6:05 PM   #6 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
I think I did it on my own. I looked at how to use preg_replace, because I never have before..

PHP Code:
<?php

$pattern 
= array('/@([A-Za-z0-9]*)/');
$replace = array('@<a href="http://twitter.com/$1">$1</a>');
$subject "@mrheadrick i think i figured it out on my own!";

echo 
preg_replace($pattern$replace$subject1);
?>
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 6:06 PM   #7 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
I just realized that this works for people with alphanumeric names, but not underscores which are allowed by Twitter. I think that's all they allow though, right? a-z, 0-9, and _.
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 6:08 PM   #8 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
And this only seems to work with the first one, not multiples...
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old February 9th, 2009, 6:12 PM   #9 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,138 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
Yours works! Thanks a ton.
__________________
fury™ - not helping the situation since 1987
robmonroe.net | Twitter | Foursquare
fury is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On