Skip to content
WJunction - Webmaster Forum

Snippets & Random Crap (Linkify text links included)

Status
Not open for further replies.

JmZ

(╯°□°)╯︵ ┻━┻
1,789
2008
729
Linkify text links on page load using JQuery:
Code:
$(function() {
    var sexyregex = /^http:\/\/(hotfile\.com|rapidshare\.com|megaupload\.com)\/[\S]+$/;
    $('body *').contents().filter(function() {
        return this.nodeType == 3 &&
            $(this).text().trim() !== '' &&
            $(this).text().trim().match(sexyregex);
    }).each(function() {
        $(this).replaceWith('<a href="' +
                     $(this).text().trim() +
                     '" target="_blank" rel="bitches_dont_know_bout_my_regex">' +
                     $(this).text().trim() +
                     '</a>');
    });
});
Alter the regex to allow other hosts (Corrup posted this for me previously when i was banned, thanks corrup).

One Liner'ing Stuff
Code:
if($x == 'abc') {
     somefunc();
     return false;
}
messing around with logic, one liner'd:
Code:
if($x == 'abc') return !(somefunc() || true);

SEO'ing a string
I see people str_replace'ing special characters and such to turn 'abc def (2005)' into 'abc-def-2005', but there's an easier way:
Code:
function jmzseo($s, $b='-') {
     return preg_replace('#[\W]+#', $b, $s);
}
// use as such: jmzseo('abc def (2003)') to return 'abc-def-2003'
// also can change seperator
// jmzseo('abc def (2003)', '+') = 'abc+def+2003'

P.S thanks guys for posting for me while I was banned.
 
Status
Not open for further replies.

About the author

J
(╯°□°)╯︵ ┻━┻ · Joined
1,789
Messages
729
Reactions
113
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom