Filtering user submitted data in PHP

asked May 14, 2012 in General by darkshark (1,500 points)
Hi all..
I am working on a contact form and I need to filter the user input data(posted variables), and I don’t want to do it  individually. I am looking for a way to filter the posted variables easily in PHP. Can anyone here help me please?

2 Answers

0 like 0 dislike
answered May 14, 2012 by lightSpeed (2,420 points)
PHP function to filter the user supplied data.
function filter_data($val)
  return htmlentities($val,ENT_QUOTES);
This is just a example of very simple function is PHP to filter the user submitted data.But ,you can add more code according to your requirement to make this function robust.
0 like 0 dislike
answered May 14, 2012 by expert (14,380 points)
You can also use use array_map() function to filter the posted data in PHP
using the callback function. you can filter the the posted data easily with this code
then you can access the filtered variables easilly with $post['name'] or $post['email'] etc.