Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△

エラーメッセージWarning

概要

 状態:-  閲覧数:8,193  投稿日:2011-05-11  更新日:2014-03-14  
・htmlspecialchars()へ渡すべき引数の数は1つで内容は文字列であるはずなのに、配列を渡したため警告


エラーメッセージ


Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△

エラーレベル
・警告

メッセージ
・htmlspecialchars() expects parameter 1 to be string, array given

ファイル名
・○○.php

行番号
・△△

実際に遭遇した例

 閲覧数:806 投稿日:2011-05-11 更新日:2014-03-14 

エラーメッセージ


Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△


エラー原因


・配列をhtmlspecialchars()へそのまま渡した
 
htmlspecialchars($_GET, ENT_QUOTES,'UTF-8');



対応


▼修正例
 
function h($string) {
   if (is_array($string)) {
       return array_map("h", $string);
   } else {
       return htmlspecialchars($string, ENT_QUOTES,'UTF-8');
   }
}
h($_GET);



Warning: include() [function.include]: Failed opening '**.php' for inclusion (in

Warning: Division by zero

コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ 31
2 Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△ 30
3 ( ! ) Warning: Declaration of xxxx should be compatible with 27
4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ○○.php on line △△ 26
5 SHA-1(Secure Hash Algorithm 1) 26
6 Parse error: syntax error, unexpected $end in ○○.php on line △△ 25
7 Sorry, that page does not exist. 25
8 Fatal error: Function name must be a string in /○○.php on line △△ 25
9 Parse error: syntax error, unexpected 'public' (T_PUBLIC) 25
10 Warning: Missing argument 1 for **(), called in ○○ on line △△ and defined in □□ 24
11 Warning: array_rand() [function.array-rand]: Second argument has to be between 1 24
12 Fatal error: Using $this when not in object context in /○○.php on line △△ 24
13 Warning: mb_convert_encoding(): Unable to detect character encoding 24
14 Warning: Division by zero 24
15 Parse error: syntax error, unexpected ';', expecting ')' in 23
16 Parse error: syntax error, unexpected 'new' (T_NEW) 23
17 ( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in 23
18 Fatal error: Call-time pass-by-reference has been removed in 23
19 ( ! ) Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException 23
20 Warning: include(**.php) [function.include]: failed to open stream: No such file 23
2025/2/06 9:55 更新
週間人気ページランキング / 1-30 → 2-5
順位 ページタイトル抜粋 アクセス数
1 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 10
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 9
3 curl で Cookie を使用する 4
3 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 4
3 PHPで定数を定義する方法は2種類ある / 配列定数の定義 4
4 コード例 … 「例外処理」はネストすることができる 3
4 Warning: PDO::query(): LOAD DATA LOCAL INFILE forbidden | Warning(エラーメッセージ) 3
4 http_build_queryとは? / 構文 /パラメータ 3
4 Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting | エラーメッセージ 3
5 Fatal error: Cannot redeclare 関数名() (previously declared in ファイル名:○○) in ファイル名 | Fatal error(エラーメッセージ) 2
5 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'データベースユーザー名'@'localhost' (using password: YES)' | phpMyAdmin(データベース関連) 2
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 2
5 new clone違い | 演算子 2
5 オブジェクト関係マッピング | データベース関連 2
5 array_filter | 配列 2
6 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 1
6 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 1
6 セッション単位 | セッション 1
6 htmlspecialchars / htmlentities / addslashes / mysql_real_escape_string / mysqli_real_escape_string | セキュリティ 1
6 dirname() / (__FILE__ ) / basename( dirname( __FILE__ ) ); | 関数 1
2025/2/6 1:02 更新