note 99745 added to function.dechex

From: Date: Thu, 02 Sep 2010 15:33:27 +0000
Subject: note 99745 added to function.dechex
Groups: php.notes 
Request: Send a blank email to php-notes+get-172279@lists.php.net to get a copy of this message
<?php /** * String to HEX | HEX to String. Automatic detection. * This script just takes input from the command line * and transforms an ASCII String to HEX or viceversa. * If you want to use it in a web page just change the $str variable below. * Cheers, Juan Stange.- */ $str = $_SERVER["argv"][1]; function hexEncode($str=NULL){ if(is_null($str)){ return FALSE; } $hexStr = ""; for($i=0;isset($str[$i]);$i++){ $char = dechex(ord($str[$i])); $hexStr .= $char; } return "0x".$hexStr; } function asciiEncode($str=NULL){ if(!preg_match("/^0x[A-Fa-f0-9]+/",$str)){ return FALSE; //Not a hex string } $str = substr($str,2); $asciiString = ""; for($i=0;isset($str[$i]);$i+=2){ $hexChar = substr($str,$i,2); $asciiString .= chr(hexdec($hexChar)); } return $asciiString; } $return = ($encoded=asciiEncode($str)) ? $encoded : hexEncode($str); echo $return."\n"; ?> ---- Server IP: 190.2.55.64 Probable Submitter: 200.49.158.151 ---- Manual Page -- http://www.php.net/manual/en/function.dechex.php Edit -- https://master.php.net/note/edit/99745 Del: integrated -- https://master.php.net/note/delete/99745/integrated Del: useless -- https://master.php.net/note/delete/99745/useless Del: bad code -- https://master.php.net/note/delete/99745/bad+code Del: spam -- https://master.php.net/note/delete/99745/spam Del: non-english -- https://master.php.net/note/delete/99745/non-english Del: in docs -- https://master.php.net/note/delete/99745/in+docs Del: other reasons-- https://master.php.net/note/delete/99745 Reject -- https://master.php.net/note/reject/99745 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172279) next »