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

エラーメッセージWarning

概要

 状態:-  閲覧数:8,268  投稿日: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

行番号
・△△


実際に遭遇した例

 閲覧数:1,001 投稿日: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/10/09 9:20 更新
週間人気ページランキング / 10-2 → 10-8
順位 ページタイトル抜粋 アクセス数
1 ブラウザを閉じたらセッションデータはどうなるの? | セッション 5
2 curl で Cookie を使用する 4
3 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 3
4 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in ○○.php on line △△ | Warning(エラーメッセージ) 2
4 PHPで定数を定義する方法は2種類ある / 配列定数の定義 2
4 ( ! ) Warning: file_put_contents(/a/b.jpg): failed to open stream: No such file or directory in | エラーメッセージ 2
4 or(||) | 演算子 2
4 Warning: strlen() expects parameter 1 to be string, array given in ○○.php on line △△ | Warning(エラーメッセージ) 2
4 http_build_queryとは? / 構文 /パラメータ 2
5 static修飾子 | クラスとオブジェクト 1
5 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 1
5 ブラウザを閉じたらセッションデータはどうなるの? | セッション 1
5 php-devel とは? 1
5 演算子 1
5 creating database ERROR!!: exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 table tally already exists' | SQLite(エラーメッセージ) 1
5 Warning: session_write_close(): Failed to write session data (user) | Warning(エラーメッセージ) 1
5 マジックメソッド(クラスとオブジェクト) カテゴリー 1
5 Deprecated: Assigning the return value of new by reference is deprecated | Deprecated(エラーメッセージ) 1
5 Fatal error: Cannot break/continue 1 level | Fatal error(エラーメッセージ) 1
5 Fatal error: Uncaught HeadlessChromium\Exception\OperationTimedOut: Operation timed out (3sec) in | Fatal error(エラーメッセージ) 1
2025/10/9 1:01 更新