title: isHex() and isOcta() functions
body: <p>I have Two Functions. <strong>IsOcta</strong> and <strong>isHex</strong>. Can not seem to make isHex work properly.<br>
  Issue in isHex() is that it can not omit 'x' notation of the original string <em>x23</em>. </p>
  
  <p>Original hex srting can also be <em>D1CE</em>. So adding x and then comparing wont do. </p>
  
  <p><strong>Is there any correct solution to the isHex function. Also is isOcta correct?</strong></p>
  
  <pre><code>function isHex($string){
      (int) $x=hexdec("$string");     // Input must be a String and hexdec returns NUMBER
      $y=dechex($x);          // Must be a Number and dechex returns STRING
      echo "&lt;br /&gt;isHex() - Hexa Number Reconverted: ".$y;       
  
      if($string==$y){
          echo "&lt;br /&gt; Result: Hexa ";
      }else{
          echo "&lt;br /&gt; Result: NOT Hexa";
      }   
      }
  
  
  function IsOcta($string){
      (int) $x=octdec("$string");     // Input must be a String and octdec returns NUMBER
            $y=decoct($x);            // Must be a Number and decoct returns STRING
      echo "&lt;br /&gt;IsOcta() - Octal Number Reconverted: ".$y;          
  
      if($string==$y){
      echo "&lt;br /&gt; Result: OCTAL";
      }else{
      echo "&lt;br /&gt; Result: NOT OCTAL";
      }
  
  } 
  </code></pre>
  
  <p>Here is the Call to the Functions:</p>
  
  <pre><code>$hex    =   "x23";      // STRING 
  $octa   =   "023";  // STRING 
  echo "&lt;br /    Original HEX = $hex | Original Octa = $octa &lt;br /    ";
  
  echo isHex($hex)."&lt;br /    ";   
  echo IsOcta($octa);
  </code></pre>
  
  <p>Here is the Result of the Function Call:</p>
  
  <pre><code>Original HEX = x23 | Original Octa = 023 
  
  isHex() - Hexa Number Reconverted: 23
  Result: NOT Hexa
  
  IsOcta() - Octal Number Reconverted: 23
  Result: OCTAL
  </code></pre>
  
  <p>===== COMPLETE ANSWER ====</p>
  
  <p>Thanks Layke for directing to the built in function that tests whether HEXA DECIMAL characters are present in a string or not. Also thanks mario for giving the hint to use ltrim. Both functions were needed to get isHexa or is hexadecimal function to be built. </p>
  
  <p>--- EDITED FUNCTION --</p>
  
  <pre><code>// isHEX function
  
  function isHex($strings){
  
  // Does not work as originally suggested by Layke, but thanks for directing to the resource. It does not omit 0x representation of a hexadecimal number. 
  /*
  foreach ($strings as $testcase) {
       if (ctype_xdigit($testcase)) {
          echo "&lt;br /&gt; $testcase - &lt;strong&gt;TRUE&lt;/strong&gt;, Contains only Hex&lt;br /&gt;";
      } else {
          echo "&lt;br /&gt; $testcase - False, Is not Hex";
  
     } 
  }
  */
  
     // This works CORRECTLY
     foreach ($strings as $testcase) {
          if (ctype_xdigit(ltrim($testcase , "0x"))) {
             echo "&lt;br /&gt; $testcase - &lt;strong&gt;TRUE&lt;/strong&gt;, Contains only Hex&lt;br /&gt;";
         } else {
             echo "&lt;br /&gt; $testcase - False, Is not Hex";
  
        } 
     }
  }
  
  $strings = array('AB10BC99', 'AR1012', 'x23' ,'0x12345678');
  isHex($strings); // calling
  </code></pre>
  
  <p>Probably now, is this the fool proof answer to the 'is hexadecimal' function?</p>