Nitrocosm
(Administrator)
Super Poster
Kokomo, Indiana
Posts: 1471
Joined:
3/9/2005
|
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 9 years ago on Monday, January 18th, 2016 at 6:52 am)
73's, KD8FUD
|
Nitrocosm
(Administrator)
Super Poster
Kokomo, Indiana
Posts: 1471
Joined:
3/9/2005
|
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 9 years ago on Monday, January 18th, 2016 at 6:58 am)
73's, KD8FUD
|