Tag Archives: encode
Computation of hashes
Generating hashing for files or keys is often used in programming to identify files, tables or other data collection types. There are different ways of doing this and some are efficient meaning the method of hashing is reliable unlike others … Continue reading
Different ways to generate MD5 Hash in PHP
The example below shows three ways to produce the exact same MD5 hash in PHP5. // PHP’s basic md5() function $hashA = md5(’encodeme’); // MD5 by way of the mhash extension $hashB = bin2hex(mhash(MHASH_MD5, ‘encodeme’)); // MD5 with … Continue reading
Remove non ascii characters from string in PHP
The example below will remove any non-ASCII characters from a string. <?php $str = "Remove these: äó"; $string = preg_replace(’/[^(\x20-\x7F)]*/’,”, $str); ?>
php function to encode string to utf8
use the following php function to convert a string to utf8 encoding. // Fixes the encoding to uf8 function fixEncoding($in_str) { $cur_encoding = mb_detect_encoding($in_str) ; if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) return $in_str; else return utf8_encode($in_str); } // fixEncoding
Encode url in EXTJS
We can encode urls in EXTJS using the Ext.urlEncode() function. Example: Sample Object: var selectedFood = {food1:’Dal’, food2:’Naan’,food3:’Rice’}; Convert the object to URL data: var encodedUrl = Ext.urlEncode(selectedFood); // encodedUrl is an encoded URL query string://food1=Dal&food2=Naan&food3=Rice
Encode array to JSON in EXTJS
1. Create an array called foodArray: var foodArray = new Array(); 2. Add values in the array: foodArray[0] = ‘Dal’; foodArray[1] = ‘Naan’; foodArray[2] = ‘Rice’; 3. Now, convert to JSON: var foodJson = Ext.encode(foodArray);
Encode session data to a string using PHP
Developers may want to save all the current session variables in string format and extract them back into variables at a later point. This can be achieved using session_encode and session_decode functions. <?php session_register("my_items"); $my_items = array("one", "two"); $string_items … Continue reading
Encode a bitmap file into a string using Base64 in C#
byte[] image = null; using (FileStream filestrm = new FileStream(@"C:\mypic.bmp",FileMode.Open, FileAccess.Read)) { using (BinaryReader reader = new BinaryReader(filestrm)) { img = new byte[reader.BaseStream.Length]; for (int i = 0; i < reader.BaseStream.Length; i++) { img[i] = reader.ReadByte( ); } } } … Continue reading
Encode binary data As Base64 in C#
Generally a byte[] representing some binary information, such as a bitmap is encoded into a string so that it can be sent over a binary-unfriendly transport, such as email, using Base64. The static method Convert.ToBase64String on the Convert class can … Continue reading
Create an XML-RPC Request with xmlrpc_encode_request
The process to create an XML-RPC request can be broken up into individual steps: Serialize the PHP data into XML-RPC format Create an XML-RPC request by combining HTTP headers and serialized data Make the call to the service The PHP … Continue reading
XML-RPC Base64-Encoded Binary Data Type
To transfer binary information via XML-RPC we need to encode the data in base64 (serialization) and use the base64 tags as xml tags. Example Declaration: <param> <value> <base64>UHSYDhD1423Cc0Ad3NVP4OidTd8E1kRY5Edh</base64> </value> </param> Since PHP does not have a binary data type, developers … Continue reading