我對HTML form
如何使用字符串函數來清理數組變量
if(isset($_POST['job_title'])){
foreach($_POST['job_title'] as $selected) {
$job_title[] = $selected ;
}
$job_title = json_encode($job_title);
$job_title = clean_string($job_title);
}
這個PHP代碼和這是它的SQL清除輸入所以這個時候
function clean_string($string){
global $connection;
$string = trim($string);
$string = stripslashes($string);
$string = htmlspecialchars($string);
$string = htmlentities($string);
$string = mysqli_real_escape_string($connection,$string);
return $string;
}
clean_string
功能碼代碼執行它會導致錯誤,如( 期望參數1爲字符串,數組爲)
如何解決這個問題? 在此先感謝
的問題是,什麼是你想停止與此消毒?你爲什麼使用'htmlspecialchars' [***和***](http://stackoverflow.com/questions/46483/htmlentities-vs-htmlspecialchars)'htmlentities'?通常全球清潔功能是適合的。 – Script47
你的POST數據包含什麼內容?嘗試print_r($ _ POST) –
這個變量將被插入到數據庫,所以我試圖淨化特殊字符以獲得更高的安全性! @ Script47 –