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

エラーメッセージWarning

概要

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


エラーメッセージ


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

エラーレベル
・警告

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

ファイル名
・○○.php

行番号
・△△


実際に遭遇した例

 閲覧数:885 投稿日:2014-03-14 更新日:2014-03-14 

エラーメッセージ


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


エラー原因


・ループの中でstrlen()へ配列を渡してしまった
  //全件読み込むループ
while (!feof($file)) {
//1件分のデータを読み込みます
$readdata = fgetcsv($file, 256);
//読み込んだデータを列ごとに出力
if (strlen($readdata) > 0) {
print $readdata[0] . "/" . $readdata[1]. "/" .
$readdata[2] . "/" . $readdata[3]. "<br>";
}
}



対応


・「is_array」で配列のみを渡すよう修正
  //全件読み込むループ
while (!feof($file)) {
//1件分のデータを読込
$readdata = fgetcsv($file, 256);
//読み込んだデータを列ごとに出力
if (is_array($readdata)) {
print $readdata[0] . "/" . $readdata[1]. "/" .
$readdata[2] . "/" . $readdata[3]. "<BR>";
}
}



Warning: array_rand() [function.array-rand]: Second argument has to be between 1

Warning: session_write_close(): Failed to write session data (user)

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



類似度ページランキング
順位 ページタイトル抜粋
1 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ 33
2 Warning: htmlspecialchars() expects parameter 1 to be string, array given in ○○.php on line △△ 31
3 ( ! ) Warning: Declaration of xxxx should be compatible with 29
4 SHA-1(Secure Hash Algorithm 1) 28
5 Sorry, that page does not exist. 28
6 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ○○.php on line △△ 28
7 Parse error: syntax error, unexpected $end in ○○.php on line △△ 27
8 Fatal error: Function name must be a string in /○○.php on line △△ 27
9 Parse error: syntax error, unexpected 'public' (T_PUBLIC) 27
10 Warning: Division by zero 26
11 Warning: Missing argument 1 for **(), called in ○○ on line △△ and defined in □□ 26
12 Warning: array_rand() [function.array-rand]: Second argument has to be between 1 26
13 Fatal error: Using $this when not in object context in /○○.php on line △△ 25
14 Warning: mb_convert_encoding(): Unable to detect character encoding 25
15 Parse error: syntax error, unexpected 'new' (T_NEW) 25
16 Parse error: syntax error, unexpected ';', expecting ')' in 25
17 Fatal error: Call-time pass-by-reference has been removed in 25
18 ( ! ) Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException 25
19 ( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in 25
20 session.gc_maxlifetime 25
2025/2/06 7:40 更新
週間人気ページランキング / 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 更新