Thread  RSS Handy Dandy Function Dump



# 11633 8 years ago on Mon, Jan 18 2016 at 6:49 am

This thread is for dumping small, useful helper functions that I make for various things.

First, here's a quickie using regular expressions to convert image tags to their plain text alt tags.

function img2Alt($x){
  return preg_replace('/<img(.*)alt="(.*)"(.*)\>/', "$2", $x);
}

(This post was edited 8 years ago on Monday, January 18th, 2016 at 6:52 am)

73's, KD8FUD

User Image

# 11634 8 years ago on Mon, Jan 18 2016 at 6:56 am

Here's one to generate random strings:

function generateRandomString($len){
  $o = '';
  $ascii_codes = array_values(array_merge(range(48,57),range(65,90),range(97,122)));
  $c = count($ascii_codes);
  for($i=0;$i

Here's another one that generates random (mostly) pronounceable words. You'll recognize that the testing / bot accounts have names generated by this function:

function generateRandomWord($len){
  $o = '';
  $consonants = 'bcdfghjklmnpqrstvwxyz';
  $vowels = 'aeiou';
  $cl = strlen($consonants) - 1;
  $vl = strlen($vowels) - 1;
  $v = true;
  for($i=0;$i

Now, you can use this to generate random e-mail addresses en masse and fill a page with them to cheese off spammers who collect addresses (think Spampoison):

function generateRandomEmailAddress(){
  $tlds = Array('com','org','biz','gov','co.uk','de');
  $tldc = count($tlds);
  $tld = $tlds[mt_rand(0,$tldc-1)];
  return generateRandomWord(mt_rand(3,7)).'@'.generateRandomWord(mt_rand(3,7)).'.'.$tld;
}

(This post was edited 8 years ago on Monday, January 18th, 2016 at 6:58 am)

73's, KD8FUD

User Image


Return to Index Return to topic list

Forgot password?
Currently Online
Users:0
Guests:10

Most Recently Online
Nitrocosm1 month ago
Lexica3 months ago
Wolfwood294 months ago
Miroku4 months ago
Doitsujin5 months ago