php if statement or and 28 php if statement or and
How do I change integer string to hex in php?

I’m a beginner at php so please forgive me if this seems like a noobish question. I’ve been reading tutorials and the php manual but I can figure this out.
How do I take a variable with an integer string data and output it as the hex character?
for example
$data = "65";
$the_e = "\x".$data;
echo $the_e;
?>
outputs the string “\x65″ when I want the character ‘e’. Is there a simple way to do this I’ve been looking for a work-around but I need to have the hexcode from a variable or I’d need a switch statement that handles each byte.
$data = $_POST[variable];
switch($data){
case "00":
echo "\x00";
break;
case "01":
echo "\x01";
break;
ect...
?>
I’d really rather not do that for obvious reasons. If anybody know how to do this or has a better work-around please let me know, thanks.

There are two PHP functions that does conversion between integers and characters:

$char = "e";
$int = 65;

$char == chr($int); # true, as chr(65) is 'e'
$int == ord($char); # true, as ord('e') is 65
?>

So, to summarize, chr() converts and integer to a character and ord() does the opposite.

Php Tutorials-06-if statement in php – www.vdesignourweb.com

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay


?>