title: PHP : preg_replace function for replace unicode chracters with range in a string
body: <p>I want to remove a set of characters from string. I am using preg_replace for replace unicode character with blank. </p>
  
  <p>I have some ranges for unicode characters. </p>
  
  <p>It works for following code. </p>
  
  <pre><code>$output = "Clean :this; [cnv\al?id@ non AS]CII äóchar^acters.";
  $output = preg_replace('/[\x00-\x1F]|[\x21-\x2C]|[\x3A-\x40]|[\x5B-\x5E]|[\x7B-\x7D]|[\x80-\xBF]|[\x2B0-\x36F]/','', $output); 
  echo $output; 
  </code></pre>
  
  <p>But it gives error for following code.</p>
  
  <pre><code>$output = "Clean :this; [cnv\al?id@ non AS]CII äóchar^acters."; 
  $output = preg_replace('/[\x00-\x1F]|[\x21-\x2C]|[\x3A-\x40]|[\x5B-\x5E]|[\x7B-\x7D]|[\x80-\xBF]|[\x2B0-\x36F]|[\x2000-\x2BFF]|[\x2E00-\x2E7F]|[\x3000-\x303F]|[\x1D000-\x1D24F]|[\x1F600-\x1F77F]|[\x1F000-\x1F0FF]/','', $output); 
  echo $output; 
  </code></pre>
  
  <p>Error:- preg_replace(): Compilation failed: range out of order in character class at offset 97   </p>
  
  <p>I can use for loop for remove unicode characters from string. So I need to run loop for more range.</p>
  
  <p>Can you please suggest me which is better in above code? Either for loop or preg_replace? If preg_replace is better then need solution for above error.</p>