note 102263 added to function.chr

From: Date: Fri, 04 Feb 2011 16:17:35 +0000
Subject: note 102263 added to function.chr
Groups: php.notes 
Request: Send a blank email to php-notes+get-176690@lists.php.net to get a copy of this message
Here is a sample of encoding and decoding using "chr" and "ord". <?php function Encode($txtData,$Level){ for ($j = 0;$j<$Level;$j++){ $tmpStr = ''; for ($i = 0;$i<strlen($txtData);$i++) $tmpStr .= ord(substr(strtoupper($txtData), $i, 1)); $txtData = $tmpStr; } return (strlen($Level)).$Level.$txtData; } function Decode($txtData){ $intLevel = substr($txtData, 1, substr($txtData, 0, 1)); $startStr = substr($txtData, substr($txtData, 0, 1)+1, strlen($txtData)); for ($j = 0;$j<$intLevel;$j++){ for ($i = 0;$i<strlen($startStr);$i+=2) $tmpStr .= chr(intval(substr($startStr, $i, 2))); $startStr = $tmpStr; $tmpStr = ""; } return $startStr; } echo Encode('123',4).'<br>'; echo Decode(Encode('123',5)); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 84.241.30.134 ---- Manual Page -- http://www.php.net/manual/en/function.chr.php Edit -- https://master.php.net/note/edit/102263 Del: integrated -- https://master.php.net/note/delete/102263/integrated Del: useless -- https://master.php.net/note/delete/102263/useless Del: bad code -- https://master.php.net/note/delete/102263/bad+code Del: spam -- https://master.php.net/note/delete/102263/spam Del: non-english -- https://master.php.net/note/delete/102263/non-english Del: in docs -- https://master.php.net/note/delete/102263/in+docs Del: other reasons-- https://master.php.net/note/delete/102263 Reject -- https://master.php.net/note/reject/102263 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#176690) next »