PHP需要修剪所有$ _POST变量 [英] PHP need to trim all the $_POST variables
本文介绍了PHP需要修剪所有$ _POST变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在异常情况下需要您的帮助.我需要修剪所有$ _POST变量.
Need you help in an unusal situation. I need to trim all the $_POST variables.
我有什么方法可以一次完成,即使用一个功能吗?
Is there any way I can do it at a single shot i.e., using a single function?
我知道trim($ _ POST)不会做,我必须做一些类似的功能
I know trim($_POST) won't do, I have to make some function like
function sanatize_post(){
foreach ($_POST as $key => $val)
$_POST[$key] = trim($val);
}
但是,如果您还有其他建议或意见,请帮助我.
But, if you have any other suggestion or comment, please help me.
谢谢
推荐答案
将array_walk
与自定义函数一起使用
use array_walk
with a custom function
$clean_values = array();
array_walk($_POST, 'sanitize_post');
function sanitize_post($item, $key)
{
$clean_values[$key] = trim($item);
//optional further cleaning ex) htmlentities
}
这篇关于PHP需要修剪所有$ _POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文