sprintf() and hexadecimal formatting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

sprintf() and hexadecimal formatting

Post by Chris Corbyn »

I like to think I'm pretty clued up on how to use sprintf()/printf() to generating strings with the correct format, but I wonder of somebody can help me rule-out the possibility of doing this...

Code: Select all

$val = 0xAFED78; //Pure integer value in hex
printf(" ... something to with =%02X ? ... ", $val);
 
/*
=AF=ED=78
*/
I don't think it's possible to do a single call and it requires some pre-processing of $val, but just on the off-chance does anyone know if there's a way?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: sprintf() and hexadecimal formatting

Post by Weirdan »

You mean your format string is controlled by a malicious person? You're screwed then.
Post Reply