$GetDatas 数据 =
PHPCode 部分A
[PHPCode]
$word = "PHPCode 部分A";
[/PHPCODE]
PHPCode 部分B
[PHPCode]
$word = "PHPCode 部分B";
[/PHPCODE]PHPCode 部分C
[PHPCode]
$word = "PHPCode 部分C";
[/PHPCODE]运行结果 =
PHPCode 部分A$word = "PHPCode 部分A";$word = "PHPCode 部分B";$word = "PHPCode 部分C";PHPCode 部分B
PHPCode 部分C public static function PHPCodeShow($content, $widget)
{ $GetDatas = $widget->text; $GetDatas = htmlspecialchars($GetDatas); $GetDatas = nl2br($GetDatas);
$PHPCodeTag = "|\[PHPCode\](.*?)\[\/PHPCode\]|ius";
$PHPCodeShow = '';
if (preg_match_all($PHPCodeTag, $GetDatas, $PHPCode))
{ for ($num = 0; $num < count($PHPCode[0]); $num++)
{
$PHPCodeShow .= $PHPCode[1][$num];
}
$PHPCodeOutPut = '';
$P = array($PHPCodeShow);
$split = preg_split($PHPCodeTag,$GetDatas);
for($i = 0; $i < count($split); $i++)
{
$PHPCodeOutPut .= $split[$i].$P[$i]; //出错行
}
echo $PHPCodeOutPut;
}
Notice: Undefined offset: 1 in D:\..php on line 115Notice: Undefined offset: 2 in D:\..php on line 115Notice: Undefined offset: 3 in D:\..php on line 115
PHPCode 部分A
[PHPCode]
$word = "PHPCode 部分A";
[/PHPCODE]
PHPCode 部分B
[PHPCode]
$word = "PHPCode 部分B";
[/PHPCODE]PHPCode 部分C
[PHPCode]
$word = "PHPCode 部分C";
[/PHPCODE]运行结果 =
PHPCode 部分A$word = "PHPCode 部分A";$word = "PHPCode 部分B";$word = "PHPCode 部分C";PHPCode 部分B
PHPCode 部分C public static function PHPCodeShow($content, $widget)
{ $GetDatas = $widget->text; $GetDatas = htmlspecialchars($GetDatas); $GetDatas = nl2br($GetDatas);
$PHPCodeTag = "|\[PHPCode\](.*?)\[\/PHPCode\]|ius";
$PHPCodeShow = '';
if (preg_match_all($PHPCodeTag, $GetDatas, $PHPCode))
{ for ($num = 0; $num < count($PHPCode[0]); $num++)
{
$PHPCodeShow .= $PHPCode[1][$num];
}
$PHPCodeOutPut = '';
$P = array($PHPCodeShow);
$split = preg_split($PHPCodeTag,$GetDatas);
for($i = 0; $i < count($split); $i++)
{
$PHPCodeOutPut .= $split[$i].$P[$i]; //出错行
}
echo $PHPCodeOutPut;
}
Notice: Undefined offset: 1 in D:\..php on line 115Notice: Undefined offset: 2 in D:\..php on line 115Notice: Undefined offset: 3 in D:\..php on line 115
for($i = 0; $i < count($split); $i++)
{
$PHPCodeOutPut .= $split[$i].$P[$i]; //出错行
}$PHPCodeShow 是一个串
所以 $P 是一个只有一个元素的一维数组,下标只有 0
但是 $split 可能有多个元素,也就是 $i 可能大于 0
$P[$i] 你用不存在的下标取值,当然是要报错的。
虽然可以通过屏蔽 Notice 级别错误的检查来回避出错信息的出现,但你的程序是不健壮的
期望值是
PHPCode 部分A
$word = "PHPCode 部分A";PHPCode 部分B
$word = "PHPCode 部分B";PHPCode 部分C
$word = "PHPCode 部分C";