Jump to content

Str_replace - replacing text and sorting in tables with background and colored text


Kimzer

Recommended Posts

<?php
$file
= "C:\folder\log.txt";
// file() (PHP 3, PHP 4, PHP 5)
// read the file into array
$ar_log = file($file);
// flip the array
$ar_log = array_reverse($ar_log);
// convert array to string
$log = implode('',$ar_log);
// print result
echo '<pre>'.$log.'</pre>';
?>

 

 

I have this bit of code that outputs some logs from a txt file in descending order for me. This works absolutely awesome and does the trick.

However, i am trying to replace some text wich is in that .txt so that it changes on the output of the website.

The text i am trying to replace is Arma-AH.net to DayZNorway.com

Now i have fiddled around with str_replace but i simply cannot get it to work. I am not good at this so i desperately need some assistance.

I also would have loved to be able to filter out quotation marks and place it all in tables with text explaining what each table includes. Such as Playername, Killed, weapon, and so on.. You get the jist.

Preferrably on a black background with a colored text if doable..

Then i have this second script.

<?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.";
}
?>

 

Wich does some of the same, atleast for the replacing. But here i just want it to display in descending order instead. Its far from pretty, i know, so if someone wants to clean it up aswell. That would be much appreciated too.

 

Hope someone can help out a php noobie here :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.