note 55509 added to function.str-shuffle

From: Date: Fri, 05 Aug 2005 11:20:07 +0000
Subject: note 55509 added to function.str-shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-93122@lists.php.net to get a copy of this message
(correction) 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]/ie', '(rand(0,1) ? \'$0\' ^ str_pad(\'\', strlen(\'$0\'), \' \') : \'$0\')', $input); and for good measure: Upper case: preg_replace('/[a-z]/e', '\'$0\' & str_pad(\'\', strlen(\'$0\'), chr(223))', $input); Lower case: preg_replace('/[A-Z]/e', '\'$0\' | str_pad(\'\', strlen(\'$0\'), \' \')', $input); ---- Manual Page -- http://www.php.net/manual/en/function.str-shuffle.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55509 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55509&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55509&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93122) next »