2011-05-30 48 views
0

顯示 「 - Debug: Undefined variable: wordscut on line 168 of /wp-content/themeWordPress的_e功能

function cutstr($string, $length) { 
     $string =strip_tags($string); 
     preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]| 
[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $info); 
     for($i=0; $i<count($info[0]); $i++) { 
       $wordscut.= $info[0][$i]; 
       $j= ord($info[0][$i]) > 127 ? $j + 2 : $j + 1; 
       if ($j > $length - 3) { 
         return $wordscut." ..."; 
       } 
     } 
     return join('', $info[0]); 
} 

上面是我的職責。我知道在PHP中,這是正確的,如果一個變量沒有被宣佈之前它被使用。爲什麼它顯示「Undefined variable: wordscut, j .....謝謝你。

2,*必需:Non-printable characters were found in the '''functions.php'''文件。檢查該文件中的錯誤。

什麼是Non-printable characters。如何糾正呢?謝謝。

+0

什麼相關性'_e()'? #2問題的 – Sampson 2011-05-30 04:21:25

+0

。最好把它分解成另一個問題。 – ariefbayu 2011-05-30 04:35:03

回答

1

這是一個典型的一個錯誤。

當PHP啓動腳本中,$ wordscut沒有定義。當您運行時

$wordscut .= "sometext"; 

的代碼實際上做

$wordscut = $wordscut . "sometext"; 

在這一點上,$ wordscut不可用,從而發生未定義的變量錯誤。

爲了解決這個問題,添加

$wordscut = ''; 

for($i=0; $i<count($info[0]); $i++) { 
+0

但它也顯示$ j沒有定義,如何expalin呢?謝謝 – zhuanzhou 2011-05-30 04:58:57

+1

看看你的帖子:'$ j = ord($ info [0] [$ i])> 127? $ j + 2:$ j + 1;'。在這一點上,PHP不識別'$ j'。但是,在同一行中,你稱它爲('$ j + 2'&'$ j + 1')。 PHP將首先解析,然後將結果設置爲「$ j」。這就是爲什麼你得到未定義的變量。爲了解決這個問題,在循環前加''j = 0;'' – ariefbayu 2011-05-30 05:27:54

+0

謝謝你,你知道如何解決問題#2嗎? – zhuanzhou 2011-05-30 05:36:00