我收到此错误:
A PHP Error was encountered Severity: Warning Message: strip_tags() expects parameter 1 to be string, array given Filename: inscription/loginform3.php Line Number: 19
这是代码:
echo form_open_multipart('user/register_step_3');
// Loop through the POST variables passed from the previous page
foreach ($_POST as $key => $value){
$value = htmlentities(stripslashes(strip_tags($value)));
echo form_hidden($key, $value);
}
第 19 行的代码:
$value = htmlentities(stripslashes(strip_tags($value)));
请帮我解决这个问题。
最佳答案
请检查您的表单是否有任何以数组形式给出的输入标记 意思是:
<input type="checkbox" name="check[]" />
如果存在数组字段,您需要再使用一个内部循环,例如:
foreach ($_POST as $key => $value){
if(is_array($value)){
// Inner loop
foreach ($value as $k => $v){
// Code
}
}else{
$value = htmlentities(stripslashes(strip_tags($value)));
echo form_hidden($key, $value);
}
}
否则请尝试以下代码:
foreach ($_POST as $key => $value){
$val = htmlentities(stripslashes(strip_tags($_POST[$key])));
echo form_hidden($key, $val);
}
关于php - CodeIgniter 遇到 PHP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17847368/