XSS filtering function in PHP

前端 未结 10 1671
轮回少年
轮回少年 2020-11-27 11:18

Does anyone know of a good function out there for filtering generic input from forms? Zend_Filter_input seems to require prior knowledge of the contents of the input and I\'

10条回答
  •  旧时难觅i
    2020-11-27 11:47

    Simple way? Use strip_tags():

    $str = strip_tags($input);
    

    You can also use filter_var() for that:

    $str = filter_var($input, FILTER_SANITIZE_STRING);
    

    The advantage of filter_var() is that you can control the behaviour by, for example, stripping or encoding low and high characters.

    Here is a list of sanitizing filters.

提交回复
热议问题