I have an HTML form that a user can input text into a title field, I then have php creating an HTML file called title.html
My problem is that users can input spaces and apostrophes into the title field that can’t be used in the html file name. I replaced the spaces with underscores by using:
$FileName = str_replace(" ", "_", $UserInput);
However, I can’t seem to remove single-quotes? I have tried using:
$FileName = preg_replace("/'/", '', $UserInput);
but this took test's and turned it into test\s.html.
Using your current str_replace method:
While it’s hard to see, the first argument is a double quote followed by a single quote followed by a double quote. The second argument is two double quotes with nothing in between.
With str_replace, you could even have an array of strings you want to remove entirely: