title: converting hexadecimal to decimal php
body: <p>I have to convert hexadecimal to decimal with PHP (without using <code>hexdec</code>) for my homework, but my code does not convert properly.</p>
  
  <p>For example, when I use the function <code>HexToDez ("1F4");</code>, the answer should be 500, not 1.</p>
  
  <p>Why is it not working? </p>
  
  <p>the code</p>
  
  <pre><code>&lt;?php    
  function Replace ($i)
  {
  switch (strToLower ($i))
    {
    case "a" : return 10;
    case "b" : return 11;
    case "c" : return 12;
    case "d" : return 13;
    case "e" : return 14;
    case "f" : return 15;
    default  : return $i;
    }
  }
  
  function HexToDez($i) # 1F4
  {
      $input=$i;
      $num=strlen ($input) ;
      $pos=0;
      $output="";
      $hochzahl="";
      while($pos&lt;$num)
      {
          $mid = substr ($input, $pos, 1);
          $pos++;
          return $end=Replace ($mid);
      }   
      while ($end != 0){
          $zahl = $input%10;
          $output += $zahl*pow(16, $hochzahl);
          $end = $end/10;
          $hochzahl++;    
      }
      echo $output;
  } 
  ?&gt;
  </code></pre>