title: Why is intval() returning 0 here?
body: <p>So based on the documentation, if I put a string inside intval() it should return an integer of said string. However, when I feed it a variable with a string value of a number, it is spitting out '0' instead of the appropriate number.</p>
  
  <p>This code is what I've whipped up to attempt to convert the page number of the image in the archive section of my site into the title.</p>
  
  <pre><code>&lt;?php
      $filename = basename($_SERVER['REQUEST_URI']);
      function countDigits($str) {
          $numDigits=0;
          for ($i=0; $i &lt; strlen($str); $i++) {
              if (is_numeric($str[$i])) {
                  $numDigits++;
              }
          }
          return $numDigits;
      }
      $digits = countDigits($filename);
      $thisPageNum = intval(substr($filename, -$digits, $digits), 10);
      if ($thisPageNum = 0) {
          echo '&lt;title&gt;Unfetched Page #&lt;/title&gt;';
      }
      else {
          echo '&lt;title&gt;Archive: Page ' . $thisPageNum . '&lt;/title&gt;';
      }
  ?&gt;
  </code></pre>
  
  <p>So, attempting to find the problem revealed that intval is returning 0 instead of the appropriate number. For clarification the page name that is being grabbed for this test ends up being: <code>archive.php?p=2</code> and the digits (1) are properly counted and the substring (2) is correctly fetched. Furthermore, the if statement at the end that checks if $thisPageNum = 0 isn't firing and giving the error message. It's always giving the Else echo (Returning Archive: Page 0).</p>
  
  <p>So I suppose I have three questions here. Am I misunderstanding how intval() works entirely? Is it not a way of doing str2int? Is there a different way of achieving the str2int result I'm requiring for this?</p>
  
  <p>Disclaimer: I've been messing with php for about 24 hours. If you start slipping in a bunch of crazy things like gets please do explain what they are doing as I may not understand and I do not like to use code I do not understand. Thanks, :)</p>
  
  <p>EDIT: I fixed the silly little errors I made by typing this out here. Those two errors were not actually present.</p>