title: I am trying to remove special characters but keep spaces and _ not working PHP
body: <p>This is my code. I am using regex to check when creating a folder it does not contain special characters but allow spaces and underscores in the name. This code does not work but i cannot find the reason why. Please help me </p>
  
  <pre><code>if (preg_replace("/[^\w ]+/", "", $filename))
  {
    echo 'A file name can not contain The Following Characters: \ / : * ? " &lt; &gt; | %';
  }else{
    // do something
  }
  </code></pre>