【问题标题】:PHP Warning: strpos() expects parameter 1 to be string, array givenPHP 警告:strpos() 期望参数 1 是字符串,给定数组
【发布时间】:2016-02-16 12:22:06
【问题描述】:

在这个question 中,我看到$handle = @fopen($thumb, 'r'); 更改为$handle = @file_get_contents($thumb); 的位置,因为他需要使用file_get_contents 作为字符串。

我遇到了同样的错误,但我没有看到需要更改的 fopen() 元素?这需要在哪里发生?

} elseif( strpos($post_id, 'user_') !== false ) {

    $user_id = str_replace('user_', '', $post_id);
    $user_id = intval( $user_id );

    $v = get_user_meta( $user_id, $field['name'], false );

    // value is an array
    if( isset($v[0]) ) {

        $value = $v[0];

    }

【问题讨论】:

  • 在strpos之前,使用var_dump($post_id)查看变量的值。

标签: php


【解决方案1】:

从错误 $post_id 是一个数组。 strpos的一个例子

$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

在您的代码print_r($post_id) 中查看包含的值

 strpos($post_id, 'user_')//here $post_id is array

【讨论】:

    【解决方案2】:

    函数strpos()用于比较字符串,并且您已将数组作为第一个参数传递。

    $post_id 可能是一个数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 2023-01-17
      • 2018-07-04
      • 2021-12-29
      相关资源
      最近更新 更多