title: PHP: Detect invalid characters in a text
body: <p>I would like to parse user inputs with PHP. I need a function which tells me if there are invalid characters in the text or not. My draft looks as follows:</p>
  
  <pre><code>&lt;?php
  function contains_invalid_characters($text) {
      for ($i = 0; $i &lt; 3; $i++) {
          $text = html_entity_decode($text); // decode html entities
      } // loop is used for repeatedly html encoded entities
      $found = preg_match(...);
      return $found;
  }
  ?&gt;
  </code></pre>
  
  <p>The function should return TRUE if the input text contains invalid characters and FALSE if not. Valid characters should be:</p>
  
  <p>a-z, A-Z, 0-9, äöüß, blank space, "!§$%&amp;/()=[]\?.:,;-_</p>
  
  <p>Can you tell me how to code this? Is preg_match() suitable for this purpose? It's also important that I can easily expand the function later so that it includes other characters.</p>
  
  <p>I hope you can help me. Thanks in advance!</p>