title: convert a '$_GET' hex value (string form) to hex int -- how?
body: <p>I suspect this might be a duplicate but lord if I can find it.</p>
  
  <p>I need to convert a 'mostly' hex value passed in the <code>_GET[]</code> array from string to an actual hex integer.  I say 'mostly' because the hex number passed in is not prepended with the "0x"</p>
  
  <p>The most promising thing I tried and then raised the white flag on this problem was this -- 'azk' is the name of the <code>GET[]</code> parameter passed in:</p>
  
  <pre><code>   $timeStamp = filter_input(INPUT_GET, 'azk', FILTER_SANITIZE_STRING); 
  
     //FAILS FOR HEX --&gt;  $test = (int)$timeStamp;
     //FAILS FOR HEX --&gt;  $test =  0 + $timeStamp;
  
     $retval =  sscanf($timeStamp, '%x', $test);
     var_dump(gettype($test));
     var_dump($test);
  </code></pre>
  
  <p>Here's what happens:   the user passes in an 'azk' value of <strong>531cb6d6</strong>,  which is in fact a hex value but not prepended with the '0x'.</p>
  
  <p>Despite my instructions to <code>sscanf()</code> above -- note that I specifically instruct <code>sscanf()</code> to convert the value of 'timeStamp' into a hex value by way of the '%x' flag --</p>
  
  <p>-- the <code>$test</code> value is shown, via the var_dump's above, as this:</p>
  
  <pre><code>   string(7) "integer" int(1394390742)   
  </code></pre>
  
  <p>The '1394390742' is <em>not</em> hex.  I'm not seeing why, I specifically instruct sscanf to convert to %x hex value, but this '1394390742'  is the base-10 (decimal) version of the base-16 (hexadecimal) value that got passed in, the <strong>531cb6d6</strong> value.  In other words, using "%x" is converting hex to decimal.  Not sure if that is a bug, a setting in the web server ini files somewhere, or a lack of my understanding of "%x".</p>
  
  <p>The <code>sscanf()</code> is not all I've tried, this is not exhaustive but I tried things like this, to me the most obvious choice:</p>
  
  <pre><code>   // BOTH OF THESE FAIL TO PASS HEX CHARS, BOTH RETURN THIS:   53166
   $timeStamp = filter_input(INPUT_GET, 'azk', FILTER_SANITIZE_NUMBER_INT,
                               FILTER_FLAG_ALLOW_HEX);
  
   $timeStamp = filter_input(INPUT_GET, 'azk', FILTER_VALIDATE_INT, 
                               FILTER_FLAG_ALLOW_HEX);
  </code></pre>
  
  <p>I've looked at a bunch of SO posts, I can't believe this isn't covered, but I can't find it.  If someone knows how to pull this off -- convert a hex value passed by the <code>_GET</code> as a string, then convert to a hex value -- I would be in your debt.</p>