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:18 PM   #10 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,140 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
How hard would it be to modify for hashtags?

EDIT: I did it. Just changed the 's to #'s and the link format. Thanks again.
__________________
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:25 PM   #11 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,511 posts
Gave thanks: 21
Thanked 104 times
Modify yours to be:

PHP Code:
<?php

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

echo 
preg_replace($pattern$replace$subject);
?>
That 1 in the function call limits it to 1 replacement so take that out unless that is what you intended. This also works with underscores in the name. So here now is my new code and results:

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>\n";
// add extra space this time

echo rtrim(twitterify($tweet.' '))."<br>\n";

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

echo 
preg_replace($pattern$replace$subject);

?>
HTML Output:
Code:
@<a href="http://twitter.com/mrheadrick" target="_blank">mrheadrick</a> Hey @<a href="http://twitter.com/mozunk" target="_blank">mozunk</a>! Go check out <a href="http://digsby.com" target="_blank">http://digsby.com</a> -- <a href="http://www.markheadrick.com" target="_blank">http://www.markheadrick.com</a> I think you will like it. @robmonroe<br>
@<a href="http://twitter.com/mrheadrick" target="_blank">mrheadrick</a> Hey @<a href="http://twitter.com/mozunk" target="_blank">mozunk</a>! Go check out <a href="http://digsby.com" target="_blank">http://digsby.com</a> -- <a href="http://www.markheadrick.com" target="_blank">http://www.markheadrick.com</a> I think you will like it. @<a href="http://twitter.com/robmonroe" target="_blank">robmonroe</a><br>

@<a href="http://twitter.com/mrheadrick">mrheadrick</a> i think i @<a href="http://twitter.com/some_guy">some_guy</a> figured it out on my own!
__________________
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:33 PM   #12 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,511 posts
Gave thanks: 21
Thanked 104 times
Cool.. anyway, thanks for pointing me to that code.. made it easier for me.
__________________
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:39 PM   #13 (permalink)
Surpass Fan
Super #1
 
fury's Avatar
 
Joined in Dec 2005
Lives in MN > USA
Hosted on pass84
2,140 posts
Gave thanks: 89
Thanked 112 times
Send a message via AIM to fury Send a message via Skype™ to fury
Yeah I just found an example on PHP.net and tried to modify it to fit my needs. Didn't read too deeply into it. That's how I learn most of my stuff.. I just modify other snippets to meet my needs. Thanks for your help. It's for my daily digest of tweets, an example can be seen here with the new code

http://www.robmonroe.net/twitter/tes..._mytwitter.php

May need to find a new symbol to use for the link to the tweet at the end of the line now since hashtags link...
__________________
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 10th, 2009, 12:58 PM   #14 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,230 posts
Gave thanks: 49
Thanked 136 times
Just wanted to peep in... if you're using an embed script or something that doesn't do parsing, it can be done with JavaScript too.

Viviti Tip: Twitter status parsing - Mike Haugland

All you'd have to do is put the tweet text in a class of "tweet_text", add the code from the link.
H 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