note 55506 deleted from function.str-shuffle by aidan

From: Date: Fri, 05 Aug 2005 11:31:35 +0000
Subject: note 55506 deleted from function.str-shuffle by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93124@lists.php.net to get a copy of this message
Note Submitter: Qube, Efnet #php ---- I balked at the loop method used below in inverting and randomising capitalisation and released that we just need to flip the bit (3rd bit or 6th depending on what way you look at it) and it would cause the case change in a character. Full code and example: http://www.pgregg.com/projects/php/code/str_case.php (append an s to the url to get the .phps source) I came up with a method and thanks to arpad (optimising as ever! :) we now have: Invert case: preg_replace('/[a-z]/ie', '\'$0\' ^ str_pad(\'\', strlen(\'$0\'), \' \')', $input); Randomise case: preg_replace('/[a-z]/e', '(rand(0,1) ? \'$0\' ^ str_pad(\'\', strlen(\'$0\'), \' \') : \'$0\')', $input); and for good measure: Upper case: preg_replace('/[a-z]/ie', '\'$0\' & str_pad(\'\', strlen(\'$0\'), chr(223))', $input); Lower case: preg_replace('/[A-Z]/e', '\'$0\' | str_pad(\'\', strlen(\'$0\'), \' \')', $input);

« previous php.notes (#93124) next »