2015-02-10 54 views
-2

替換輸出中的單詞。 PHP

<?php 
 
\t $file = 'C:\wamp\www\Killboard\EPChernarus1\PhitLog.txt'; 
 
\t $searchfor = 'Chernarus'; 
 
    header('Content-Type: text/html'); 
 
    $contents = file_get_contents($file); 
 
\t $contents = str_replace("(ArmA-AH.net)", "(DayZNorway.com)", $contents); 
 
    $pattern = preg_quote($searchfor, '/'); 
 
\t $contents = str_replace("DayZ Instance: 11", " Map: Chernarus ", $contents); 
 
    $pattern = "/^.*$pattern.*$/m"; 
 
\t $contents = str_replace("PKILL", "Player Killed", $contents); 
 
\t $contents = str_replace("CLOG", "Combat Logged", $contents); 
 

 
if(preg_match_all($pattern, $contents, $matches)){ 
 
\t echo "<strong>"; 
 
    echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;color:#2983CB'>Killboard Epoch Chernarus: <br>"; 
 
\t echo '', implode(" <br>", $matches[0]); 
 
\t echo "</strong>"; 
 
    } 
 
else 
 
\t { 
 
\t echo "No kills yet. Looks like everyone is playing nice."; 
 
    } 
 
?>

在這裏有很大幫助後,代碼現在看起來這^ 現在我想包括下面的代碼。 因此它會將武器類重命名爲更友好的用戶名。 我已經包含了它尋找的兩個.php文件,但我不確定我放置它的位置,如果它甚至會像這樣運行,那麼我懷疑。

可能有人

\t \t if ($line_type == 'kill') { 
 
\t \t \t include("killfeed_weapon_classnames.php"); 
 
\t \t \t include("killfeed_weapon_cleannames.php"); 
 
\t \t \t $swap_key = array_search($line_varlist['weapon'], $wcn); 
 
\t \t \t if($swap_key != false) { $line_varlist['weapon'] = $wn[$swap_key]; } 
 
\t \t }

+0

旁註:我無法改變它登錄到PhitLog.txt文件的方式 – 2015-02-10 14:05:40

+0

您是否嘗試過使用替換正則表達式? – 2015-02-10 14:11:34

+0

'str_replace',簡單地說。 – ascx 2015-02-10 14:16:20

回答

0

所有預浸匹配之前和之後$內容使用:

$contents = str_replace("(Arma-AH.net)", "(DayZNorway.com)", $contents); 

編輯忘了括號和下一個問題。我不打算只給你下一部分,但看看下面的例子,並按照此應該幫助你實現你想要的下一個問題。

$myArray = array("firstName" =>"sam", "secondName" => "billy", "thirdName" => "sally"); 


$nameKey = array_search("billy", $myArray); 

echo $nameKey; 

if($nameKey){ 
    $myArray[$nameKey] = "Tom"; 
} 

print_r($myArray); 
+0

試過這個,不能得到那個工作。 – 2015-02-10 14:25:38

+0

編輯我忘了括號。如果這仍然不起作用,就把它放在輸出之前的循環中。所以在你的內爆匹配之前就行了。在比賽[0] – Asheliahut 2015-02-10 14:30:58

+0

做它仍然沒有工作。你能告訴我你的意思嗎?我可能會做錯 – 2015-02-10 14:35:44

0
<?php 
    $file = 'C:\wamp\www\Killboard\EPChernarus1\PhitLog.txt'; 
    $searchfor = 'Chernarus'; 
    header('Content-Type: text/html'); 
    $contents = file_get_contents($file); 
    $contents = str_replace("(ArmA-AH.net)", "(DayZNorway.com)", $contents); 
    $pattern = preg_quote($searchfor, '/'); 
    $contents = str_replace("DayZ Instance: 11", " Map: Chernarus ", $contents); 
    $pattern = "/^.*$pattern.*$/m"; 
    $contents = str_replace("PKILL", "Player Killed", $contents); 
    $contents = str_replace("CLOG", "Combat Logged", $contents); 

if(preg_match_all($pattern, $contents, $matches)){ 
    echo "<strong>"; 
    echo "<div style ='font:11px/21px Arial,tahoma,sans-serif;color:#2983CB'>Killboard Epoch Chernarus: <br>"; 
    echo '', implode(" <br>", $matches[0]); 
    echo "</strong>"; 
    } 
else 
    { 
    echo "No kills yet. Looks like everyone is playing nice."; 
    } 
?> 

這是我落得這樣做,現在它幾乎不漂亮,但它的工作原理。 現在我需要讓結果以降序顯示。

有人可以幫我解決這個問題嗎?