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

エラーメッセージWarning

概要

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

行番号
・△△


実際に遭遇した例

 閲覧数:957 投稿日: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/7/26 11:21 更新
週間人気ページランキング / 7-19 → 7-25
順位 ページタイトル抜粋 アクセス数
1 PHPで定数を定義する方法は2種類ある / 配列定数の定義 6
2 Parse error: syntax error, unexpected 'public' (T_PUBLIC) | Parse error(エラーメッセージ) 5
2 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 5
3 ブラウザを閉じたらセッションデータはどうなるの? | セッション 4
4 http_build_queryとは? / 構文 /パラメータ 3
4 T_CONSTANT_ENCAPSED_STRING | エラーメッセージ 3
5 オブジェクト関係マッピング | データベース関連 2
5 Fatal error: Access level to ▲::$△ must be protected (as in class ●) or weaker | Fatal error(エラーメッセージ) 2
5 Warning: PDO::query(): LOAD DATA LOCAL INFILE forbidden | Warning(エラーメッセージ) 2
5 Notice(エラーメッセージ) カテゴリー 2
5 エラーレベル | エラー設定(エラーメッセージ) 2
5 php-devel とは? 2
5 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 2
5 Fatal error: Uncaught Error: Call to a member function modify() on string | Fatal error(エラーメッセージ) 2
5 ガベージコレクション | 機能 2
5 ブラウザを閉じたらセッションデータはどうなるの? | セッション 2
5 Parse error: syntax error, unexpected ';', expecting ')' in ★★.php on line ●● | Parse error(エラーメッセージ) 2
5 ( ! ) Warning: Declaration of xxxx should be compatible with | エラーメッセージ 2
5 Notice: Array to string conversion in ★★ on line ▲▲ Array | Notice(エラーメッセージ) 2
6 ( ! ) Fatal error: Uncaught Abraham\TwitterOAuth\TwitterOAuthException: 現在この機能は一時的にご利用いただけません | Fatal error(エラーメッセージ) 1
2025/7/26 1:01 更新