title: Check if variable is a number and positive integer in PHP?
body: <p>For example, say:</p>
  
  <pre><code>&lt;?php
  
      // Grab the ID from URL, e.g. example.com/?p=123
      $post_id = $_GET['p'];
  
  ?&gt;
  </code></pre>
  
  <p>How do I check if variable <code>$post_id</code> is a number, and a positive integer at that (i.e. 0-9, not a floating point number, fraction, or a negative number)?</p>
  
  <p><strong>EDIT:</strong> Can't use <code>is_int</code> 'cause <code>$_GET</code> returns a string. Think I need to use <a href="https://stackoverflow.com/questions/19333292/check-if-variable-is-a-number-and-positive-integer-in-php#comment28640215_19333292"><code>intval()</code></a> or <a href="https://stackoverflow.com/a/3502877/1071413"><code>ctype_digit()</code></a>, with the latter seeming more appropriate. For example:</p>
  
  <pre><code>if( ctype_digit( $post_id ) ) { ... }
  </code></pre>