it shows"-- Debug: Undefined variable: wordscut on li开发者_如何学Pythonne 168 of /wp-content/theme
"
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]);
}
the above is my function. i know in php, it's right if a variable doesn't be declared before it is used.why it shows"Undefined variable: wordscut, j
..... thank you.
2,* REQUIRED: Non-printable characters were found in the '''functions.php'
'' file. You may want to check this file for errors.
what is Non-printable characters
.how to correct it? thank you.
This is one one classic bug.
When PHP started your script, $wordscut is not defined. When you run
$wordscut .= "sometext";
The code actually do
$wordscut = $wordscut . "sometext";
At this point, $wordscut is not available, thus Undefined Variable error occurred.
To fix it, add
$wordscut = '';
before
for($i=0; $i<count($info[0]); $i++) {
精彩评论