你好計算器,如果我有這個日誌這可能與文件獲取內容?
16:23:36 - [Turks] dannys
16:23:55 - *LOCAL* [Turks] stop!
16:24:08 - *LOCAL* [Turks] stop
16:24:11 - *LOCAL* [Turks] no attack
16:24:28 - *LOCAL* [Turks] stop!
16:24:35 - *LOCAL* [Turks] hey
16:24:37 - *LOCAL* [Turks] dur amk
16:24:52 - *LOCAL* [Dannys] fottiti
16:25:04 - *LOCAL* [Turks] hey
16:25:11 - *LOCAL* [Turks] hey
16:25:12 - *LOCAL* [Turks] money
16:25:36 - Turks <img=ico_swordtwo> Dannys
16:25:43 - [Turks] you fucking noob
16:26:09 - *LOCAL* [Turks] I'm giving your money!
16:26:19 - <img=ico_headshot> Turks
16:26:46 - Dannys has joined the game with ID: 416519
16:26:46 - Dannys has joined the game with ID: 416519
16:26:46 - Dannys has joined the game with ID: 416519
16:26:46 - Dannys has joined the game with ID: 416519
目前,這是我的代碼
<?php
$now = ($_POST['date']);
$file = "logs\server_log_".$now.".txt";
$searchfor = ($_POST['name']);
if ($searchfor !=""){
header('Content-Type: text/plain');
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/\b.*$pattern.*\b/i";
if(preg_match_all($pattern, $contents, $matches)){
echo "Found matches For Player ".$searchfor.":\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found For Player ".$searchfor."";
}
}
else{
echo "No Name Imput";
}
?>
現在我現在需要做的就是讓2個logsearches能夠抓住日誌雙方球員是有可能只需輸入Turks作爲第一個變量,Dannys作爲第二個變量,然後搜索日誌並例如使其文本具有不同的顏色?
希望你們能幫助我
問候格倫
編輯:我目前已經是這個
http://gyazo.com/997e6e5bd50cccedb7f6439b013c0c85
所以我基本上要就是抓住整個日誌搜索2個名稱比用顏色標記它們 新代碼
<html>
<head>
<style>
body {
white-space:pre-wrap;
font-family: TimesNewRoman, "Times New Roman", Times, Baskerville, Georgia, serif;
font-size: 14px;
color: black;
background-color: white;
}
</style>
</head>
<body>
<?php
error_reporting(E_ERROR | E_PARSE);
$now = ($_POST['date']);
$player = ($_POST['player']);
$player2 = ($_POST['player2']);
$player3 = ($_POST['player3']);
$player4 = ($_POST['player4']);
$player5 = ($_POST['player5']);
if ($player != ""){
$handle = fopen("logs/server_log_".$now.".txt", "r");
if ($handle)
{
while (($line = fgets($handle)) !== false)
{
echo preg_replace("/\w*?". preg_quote($player) ."\w*/i", "<span style=\"color: red;\">$0</span>", $line) . '';
if ($player2 !=""){
echo preg_replace("/\w*?". preg_quote($player2) ."\w*/i", "<span style=\"color: blue;\">$0</span>", $line) . '';
}
if ($player3 !=""){
echo preg_replace("/\w*?". preg_quote($player3) ."\w*/i", "<span style=\"color: yellow;\">$0</span>", $line) . '';
}
if ($player4 !=""){
echo preg_replace("/\w*?". preg_quote($player4) ."\w*/i", "<span style=\"color: green;\">$0</span>", $line) . '';
}
if ($player5 !=""){
echo preg_replace("/\w*?". preg_quote($player5) ."\w*/i", "<span style=\"color: purple;\">$0</span>", $line) . '';
}
}
}
else
{
echo "Error in opening the file.";
}
}
else {
echo "You must fill in 1 player name";
}
?>
</body>
</html>
Apperently如果您在多個變量填寫雙打整個文本我怎麼能做到這一點,使文本顯示時,只有一次,而不是5次
您可能想看看這個:http://stackoverflow.com/questions/2483844/highlight-the-word-in-the-string-if-it-contains-the-keyword – GiamPy
謝謝,我會看看,但IM退出與這些類型的代碼不好:p – Ghermans41
嗯,我有點想知道如何實現它,所以它只是抓住整個文件,而不是突出顯示2名玩家的名字 – Ghermans41