【问题标题】:strpos() and preg_split() warningstrpos() 和 preg_split() 警告
【发布时间】:2016-02-06 11:38:08
【问题描述】:

我的一个页面上有 2 个警告有问题...如果您能帮助我,我将不胜感激。

警告:strpos() 期望参数 1 是字符串

警告:preg_split() 期望参数 2 是字符串

这是我的代码:

if ( strpos($term, '+') !== false ) {
                $terms = preg_split( '/[+]+/', $term );
                if (is_array($terms) || is_object($terms)) {
                foreach ( $terms as $term ) {
                    $tax_query[] = array_merge( $tax_query_defaults, array(
                        'terms' => array( $term )
                    ) );
                } }
            } else {
                $tax_query[] = array_merge( $tax_query_defaults, array(
                    'terms' => preg_split( '/[,]+/', $term )
                ) );
            }

【问题讨论】:

  • 你的$term 需要是一个字符串
  • 一点帮助,我不是专业人士,我该怎么做?
  • 使用 var_dump($term); 并将该输出添加到您的问题中

标签: php warnings


【解决方案1】:

尝试:

if (is_string($term) && strlen($term) && strpos($term, '+') !== false ) {

在你的第一行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-12
    • 1970-01-01
    • 2014-12-07
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    相关资源
    最近更新 更多