Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Safest way to validate a textarea with PHP?

Its not like a normal input in the description I would want to safely allow commas, apostrophes and more that are also database friendly. I've already got the preg_match working to safely validate other inputs but with a description input I would want it to allow more of these grammatical signs but to do so safely.

How do you go about amending the preg_match function?

Thanks

2 Answers

Relevance
  • Jeff P
    Lv 7
    6 years ago

    Just use PHP's filter_var() function with the FILTER_SANITIZE_SPECIAL_CHARS filter. Don't mess with preg_match()--filter_var() is all you need, and this is what it is designed for.

  • ?
    Lv 6
    6 years ago

    wrap it in mysqli_escape_string... like mysqli_escape_string($textarea_content); ... or look up prepared statements (PDO). Which is a much better and safer way to insert data in to a database and automatically escapes your data.

Still have questions? Get your answers by asking now.