1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Hexadecimal input string must have an even length

Discussion in 'PHP' started by moath11, Jul 29, 2014.

Thread Status:
Not open for further replies.
  1. #1
    i have a script the parse out the hexa parameters ?aa=[Hexa] from a file and print that parsed data using after convert it using hex2bin

    $text[] = hex2bin($val[1]);

    the problem is i getting an error
    PHP Warning: hex2bin(): Hexadecimal input string must have an even length in line 11
    Line 11: $text[] = hex2bin($val[1]);




    the file that have the data has a lot of lines

    the script work only when the script has lines that contain the hexa parameters like this
    can anyone help me
     
    moath11, Jul 29, 2014 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Why did you remove your question from stack overflow? You probably would've got faster answers there IMO.

    How are those inputs created? It seems to be that the data is malformed which have to be corrected.
     
    ThePHPMaster, Jul 29, 2014 IP
  3. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    thanks for replay,
    i removed it for some reason,
    anyway, i will show you what this script doing
    basically there's a log file contains a referrer urls, and the urls has a parameter ?aa=[HEXA] and i try to make this script parse out that hexa values from the parameter aa in the urls


    but after parsing that parameters and convert that hexa to string using $text[] = hex2bin($val[1]);
    i got that error

    here's the important code


    $pos = strpos($val[1], '"');
    $val[1] = substr($val[1], 0, $pos);
    $text[] = hex2bin($val[1]);

    }
    fclose($file);
    $text = array_reverse($text);
    $text = array_unique($text);
    $text = array_merge($text);
    $count = count($text);
    for ($x=0;$x<$count;$x++){
    $final[$x] = array('value' => "$text[$x]" );
    }
    echo json_encode($final);
     
    moath11, Jul 29, 2014 IP
  4. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #4
    You will need to check where the hex code is being generated and fix it there.
     
    ThePHPMaster, Jul 29, 2014 IP
  5. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #5

    Hex needs to have 16 integers (base 16) ranging from 0 to F. Your error suggests there's an odd number of integers, any odd number not equalling 16 from the first two lines highlighted above. Simple thing to do here is to echo the string out, echo $val[1]; and count the output integers rendered.

    From there you should be able to fix the problem by correcting strpos and substr respectively.


    .
     
    ROOFIS, Jul 29, 2014 IP
  6. moath11

    moath11 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    T
    thanks for replay
    can you correct the code for me , i'm new to programming

    thank you
     
    moath11, Jul 30, 2014 IP
Thread Status:
Not open for further replies.