title: PHP: Best method to extract numbers from a string
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4175941/a-simple-function-for-return-number-from-string-in-php">a simple function for return number from string in php</a>  </p>
  </blockquote>
  
  
  
  <p>What's the best/most efficient method to extract a specific set of numbers from a string?  For example: I want to get the set of numbers immediately after Case# in sring "blah blah Case#004522 blah blah".  I imagine the number of numeric characters after Case# will always be the same but I would like the code to not make that assumption as I have been.</p>
  
  <p>So far I have been using a strpos method to locate Case# and then pull a specific number of characters afterwords using substr.  I just feel like this is clunky.  Maybe preg_match would be more effective or simplified?</p>
  
  <pre><code>$text = "blah blah Case#004552 blah blah";
  $find = strpos($text,'Case#');
  if ( $find )
    $numbers = substr($text, $find+5, 6);
  </code></pre>