title: PHP: fastest way to check for invalid characters (all but a-z, A-Z, 0-9, #, -, ., $)?
body: <p>I have to check the buffer input to a PHP socket server as fast as possible. To do so, I need to know if the input message $buffer contains any other character(s) than the following: a-z, A-Z, 0-9, #, -, . and $</p>
  
  <p>I'm currently using the following ereg function, but wonder if there are ways to optimize the speed. Should I maybe use a different function, or a different regex?</p>
  
  <pre><code>if (ereg("[A-Za-z0-9]\.\#\-\$", $buffer) === false)
  {
      echo "buffer only contains valid characters: a-z, A-Z, 0-9, #, -, ., $";
  }
  </code></pre>