function hex2bin($str) {
$bin = "";
$i = 0;
do {
$bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
$i += 2;
} while ($i < strlen($str));
return $bin;
}
Xampp is telling me theres something wrong on the last line (174) which would be the }, but there isn't a problem with it at all
Ah we-a blaze the fyah, make it bun dem!
You don't index into arrays with curly braces "{}" to index arrays in PHP, you use square ones [].
i.e:
Should actually beCode:$bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
However this code isn't going to do what the function name implies (convert a hexadecimal string into a binary string).Code:$bin .= chr(hexdec($str[$i].$str[$i + 1]));
You can win the rat race,Originally Posted by Jeremy S. Anderson
But you're still nothing but a fucking RAT.
++Latest Projects++
[Open Source] Injection Library
Simple PE Cipher
FilthyHooker - Simple Hooking Class
CLR Injector - Inject .NET dlls with ease
Simple Injection - An in-depth look
MPGH's .NET SDK
eJect - Simple Injector
Basic PE Explorer (BETA)
I know, It's not my original code, i'm setting up a server, actually and it was one of the errors it was recieving.
It doesn't matter. PHP is weird, but still a nice language. Curly braces (a.k.a. curly brackets: { }) as well as braces (a.k.a. brackets: [ ]) are just fine. People tend to use brackets because that looks better.
@Cyaphex Do you still need help? Cause I might have the solution for you. You should clearify your question how ever.
Edit:
Both $convertFrom and $convertTo have to be between 2 and 36, inclusive. Digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35. You probably don't want to change this, since you only want a hex2bin. If you want bin2hex, just swap the variables.Code:<?php $convert = '01234567890abcdef'; $convertFrom = 16; //Hexadecimal $convertTo = 2; //Binary echo base_convert($hex, $converFrom, $convertTo); ?>
Last edited by kalekip1; 08-27-2013 at 01:21 PM.