好吧,我已經試過在互聯網上搜索幾個小時了,但到目前爲止它一直沒有幫助。我試圖找出爲什麼我不斷收到通知如下通知(是的,我知道這只是一個通知,並不會暫停腳本執行):在php正則表達式中未定義的索引通知
Notice: Undefined index: 05 in [redacted_path]\script.php(31) : regexp code on line 1
這個劇本本來是作爲一個顏色爲irc頻道日誌重新定位;我從另一個網站抓取了大型功能並稍微修改以適應我的需要。信貸當然去its creator。除此之外,我對...輕微熟悉正則表達式,但不是我可以在下面發現錯誤的錯字或類似錯誤的地方。任何援助將不勝感激。
<?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);
哇,這就是我稱之爲正則表達式的盛會。哪一行是第31行? – hakre 2012-04-25 08:46:19
@hakre呃,我似乎無法得到這個格式正確,我會編輯上述問題。 – Daedalus 2012-04-25 09:02:14