2015-11-05 72 views
-2

我有一個問題,在我的一個頁面上有兩個警告......如果你能幫助我,我會非常感激。strpos()和preg_split()警告

警告: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) 
       )); 
      } 
+0

你的'$ term'需要一個字符串 – Andrew

+0

有點幫助,我不是親,我該怎麼做? –

+0

使用'var_dump($ term);'並將該輸出添加到您的問題中 – Machavity

回答

0

請嘗試:

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

在你的第一行