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

エラーメッセージWarning

概要

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

行番号
・△△


実際に遭遇した例

 閲覧数:810 投稿日: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
2024/7/27 12:47 更新
週間人気ページランキング / 7-20 → 7-26
順位 ページタイトル抜粋 アクセス数
1 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 6
2 ブラウザを閉じたらセッションデータはどうなるの? | セッション 5
3 コード例 … 「例外処理」はネストすることができる 4
4 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 3
4 PHPで定数を定義する方法は2種類ある / 配列定数の定義 3
4 Parse error: syntax error, unexpected 'new' (T_NEW) | Parse error(エラーメッセージ) 3
4 ブラウザを閉じたらセッションデータはどうなるの? | セッション 3
4 curl で Cookie を使用する 3
4 ( ! ) Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in ★★★ headless-chromium-php/vendor/wrench/wrench/lib/Wrench/Protocol/Protocol.php | エラーメッセージ 3
4 or(||) | 演算子 3
5 Composer | 依存関係マネージャ 2
5 グローバル変数 | 変数 2
5 new clone違い | 演算子 2
5 php-devel とは? 2
5 session_start() | セッション 2
5 Fatal error: Uncaught Error: Class 'Mecab_Tagger' not found in /var/www/★★.php:☆☆ | Fatal error(エラーメッセージ) 2
5 例外処理 | 制御構造 2
5 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined | Fatal error(エラーメッセージ) 2
5 関数 2
6 セッション単位 | セッション 1
2024/7/27 1:01 更新