好吧,我已经尝试在互联网上搜索了几个小时,但到目前为止它没有任何帮助。我试图弄清楚为什么我不断收到以下通知通知(是的,我知道这只是一个通知,不会停止脚本的执行):
Notice: Undefined index: 05 in [redacted_path]\script.php(31) : regexp code on line 1
该脚本旨在作为 irc 通道日志的颜色替换器;我从另一个站点获取了大型功能,并对其进行了一些修改以满足我的需要。功劳当然要归功于它的创造者。除此之外,我……对正则表达式有点熟悉,但我当然不能在下面发现有问题的错字或类似的东西。任何援助将不胜感激。
<?php
if (isset($_POST['chn'])) {
$chn = $_POST['chn'];
$str = urldecode($_POST['line']);
$filen = "logs/$chn" . "_" . date('Y_F_d') . ".html";
$str = preg_replace('/https?:\/\/[^\s"<>]+/', '<a href="$0" target="_blank">$0</a>', $str);
$logln = mirc2html($str) . "<br />\r\n";
$logln = str_replace("Â","",$logln);
file_put_contents($filen,stripcslashes($logln),FILE_APPEND);
}
if (isset($_GET['test'])) {
echo str_replace("Â","",mirc2html($_GET['test']));
}
function mirc2html($x) {
$c = array("FFF","000","00007F","009000","FF0000","7F0000","9F009F","FF7F00","FFFF00","00F800","00908F","00FFFF","0000FF","FF00FF","7F7F7F","CFD0CF");
$x = preg_replace("/\x02(.*?)((?=\x02)\x02|$)/", "<b>$1</b>", $x);
$x = preg_replace("/\x1F(.*?)((?=\x1F)\x1F|$)/", "<u>$1</u>", $x);
$x = preg_replace("/\x1D(.*?)((?=\x1D)\x1D|$)/", "<i>$1</i>", $x);
$x = preg_replace("/\x03(\d\d?),(\d\d?)(.*?)(?(?=\x03)|$)/e", "'<span style=\"color: #'.\$c['$1'].'; background-color: #'.\$c['$2'].';\">$3</span>'", $x, -1, $n1);
$x = preg_replace("/\x03(\d\d?)(.*?)(?(?=\x03)|$)/e", "'</span><span style=\"color: #'.\$c['$1'].';\">$2</span>'", $x);
$x = preg_replace("/\x03|\x0F(.*?)/", "<span style=\"color: #000; background-color: #FFF;\">$1</span>", $x);
$x = str_replace("\n","",$x);
$x = str_replace("\r","",$x);
$x = preg_replace("/\<\/span\>/","",$x,1);
$x = preg_replace("/(\<\/span\>){2}/","</span>",$x);
return $x;
}
?>
因此,违规行是:
$x = preg_replace("/\x03(\d\d?)(.*?)(?(?=\x03)|$)/e", "'</span><span style=\"color: #'.\$c['$1'].';\">$2</span>'", $x);