PHP tips and tricks

From: Date: Fri, 16 Mar 2001 15:24:45 +0000
Subject: PHP tips and tricks
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-4502@lists.php.net to get a copy of this message
Howdy, dunno if you're looking for these types of things, but I think that the following are pretty neat. They deal with bitwise operators, and the fun you can have with them. Joey # Number one. Fun. # # "I can't stop giggling" # This one's an example of bitwise ops # as applied to strings. Bitwise ops can be # used for a number of fun things, like, say, # obfuscation... or even function replacement. # (see number two) # # This loop prints "hehehehe" # print "<joey> "; for ($i=0;$i<4;$i++) { print "yes"&"no"; } # Number two: Function replacement fun. # # (strtolower and strtoupper) can be replaced by the following # bits of code. # <? function joey_strtoupper($s){ $lin = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); foreach($lin as $character) { if (eregi("([a-z])",$character)){ $character &= "_"; } $r .= $character; } return ($r); } print joey_strtoupper("Testing it out, man!!@#$"); ?> <br> <? print strtoupper("Testing it out, man!!@#$"); ?> <? function joey_strtolower($s){ $lin = preg_split('//', $s, -1, PREG_SPLIT_NO_EMPTY); foreach($lin as $character) { if (eregi("([a-z])",$character)){ $character |= " "; } $r .= $character; } return ($r); } print joey_strtolower("Testing it out, man!!@#$"); ?> <br> <? print strtolower("Testing it out, man!!@#$"); ?>

« previous php.mirrors (#4502) next »