GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   coders, check this out (https://gfy.com/showthread.php?t=446049)

Wolfy 03-19-2005 05:18 PM

coders, check this out
 
This is a plugin for wordpress that makes urls clickable. Example - it will turn the text http://www.link.com into
Code:

<a href="http://www.link.com" title="http://www.link.com" target="_blank">http://www.link.com</a>.
The only problem is that text stripped from an email automatically has this added to the url - <http://www.link.com>. I need those brackets stripped from the text so it displays correctly.

I'm sure it can be done with no more than 4 lines of code, can anyone tell me how to fix it? I'll throw in a few bucks if you want it.

(that hahahaha is 2 of these =)

Code:

function c2c_truncate_link ($url, $mode='0', $trunc_before='', $trunc_after='...') {
    if (1 hahahaha $mode) {
                $url = preg_replace("/(([a-z]+?):\\/\\/[A-Za-z0-9\-\.]+).*/i", "$1", $url);
                $url = $trunc_before . preg_replace("/([A-Za-z0-9\-\.]+\.(com|org|net|gov|edu|us|info|biz|ws|name|tv)).*/i", "$1", $url) . $trunc_after;
        } elseif (($mode > 10) && (strlen($url) > $mode)) {
                $url = $trunc_before . substr($url, 0, $mode) . $trunc_after;
        }
        return $url;
} //end c2c_truncate_link()

// mode: 0=full url; 1=host-only ;11+=number of characters to truncate after
function c2c_hyperlink_urls ($text, $mode='0', $trunc_before='', $trunc_after='...', $open_in_new_window=true) {
    $text = ' ' . $text . ' ';
    $new_win_txt = ($open_in_new_window) ? ' target="_blank"' : '';
       
    // Hyperlink Class B domains *.(com|org|net|gov|edu|us|info|biz|ws|name|tv)(/*)
    $text = preg_replace("#([\s{}\(\)\[\]])([A-Za-z0-9\-\.]+)\.(com|org|net|gov|edu|us|info|biz|ws|name|tv)((?:/[^\s{}\(\)\[\]]*[^\.,\s{}\(\)\[\]]?)?)#ie",
        "'$1<a href=\"http://$2.$3$4\" title=\"http://$2.$3$4\"$new_win_txt>' . c2c_truncate_link(\"$2.$3$4\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
        $text);

    // Hyperlink anything with an explicit protocol
    $text = preg_replace("#([\s{}\(\)\[\]])(([a-z]+?)://([A-Za-z_0-9\-]+\.([^\s{}\(\)\[\]]+[^\s,\.\;{}\(\)\[\]])))#ie",
        "'$1<a href=\"$2\" title=\"$2\"$new_win_txt>' . c2c_truncate_link(\"$4\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
                $text);

    // Hyperlink e-mail addresses
    $text = preg_replace("#([\s{}\(\)\[\]])([A-Za-z0-9\-_\.]+?)@([^\s,{}\(\)\[\]]+\.[^\s.,{}\(\)\[\]]+)#ie",
        "'$1<a href=\"mailto:$2@$3\" title=\"mailto:$2@$3\">' . c2c_truncate_link(\"$2@$3\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
        $text);

    return substr($text,1,strlen($text)-2);
} //end c2c_hyperlink_urls()


Wolfy 03-19-2005 05:26 PM

$text = preg_replace("#<((Link: http://|www)http://|www\.)(.*)>#","\\1\\2",$text);

didn't work. That leaves the closing bracket intact...

pornguy 03-19-2005 05:28 PM

Cool. Looks like it could be something to play with.

boner 2.0 03-19-2005 05:28 PM

Quote:

cig whore
Her name is Monica :2 cents:

Wolfy 03-19-2005 05:39 PM

Quote:

Originally Posted by boner 2.0
Her name is Monica :2 cents:

:1orglaugh :1orglaugh

psyko514 03-19-2005 05:47 PM

Quote:

Originally Posted by pornguy
Cool. Looks like it could be something to play with.

did you even read his post?

psyko514 03-19-2005 05:48 PM

Quote:

Originally Posted by Wolfy
$text = preg_replace("#<((Link: http://|www)http://|www\.)(.*)>#","\\1\\2",$text);

didn't work. That leaves the closing bracket intact...


can't you run the line twice? once to remove the opening bracket and once to remove the closing bracket?

my PHP knowledge is limited...

Wolfy 03-19-2005 05:56 PM

Quote:

Originally Posted by psyko514
can't you run the line twice? once to remove the opening bracket and once to remove the closing bracket?

my PHP knowledge is limited...

there's a tiny bit more to it - with that line added, it formats www.link.com to a clickable "http://.link.com/" <- there's an extra "." in the url it outputs. Also, it screws up a url written with "http://"


My php is pretty limited too, I mostly end up with :error s :winkwink:

teksonline 03-19-2005 06:26 PM

in your character class your backslashing your . before the @ i dont think you want to do that. but i havent looked at this much, i have headache, hit me up on aim and tell me exact problme i can give you the answer

Wolfy 03-19-2005 06:30 PM

it's simple, :P

$text=str_replace("<", "", $text);
$text=str_replace(">", "", $text);

I win!

teksonline 03-19-2005 06:32 PM

also I see alot of this A-Za-z0-9 which can be substituded with /w+

Wolfy 03-19-2005 06:33 PM

:thumbsup: to Cyborg for the help lol

:winkwink:

Wolfy 03-19-2005 06:41 PM

Dammit I killed Sarah Connor!! WHO WAS THAT MASKED MAN?!!!

Sorry for the confusion, I'm just passing it on. This thread is dead, somebody post *******.


All times are GMT -7. The time now is 10:03 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123