Jump to content

Recommended Posts

Hello all,

 

I'm trying to make a php file display real time chat from a game. This is what I have.

 

<?php

$file ='games_mp.log'; //This is the auto-updated chat log

 

$searchfor = 'say'; //Searches for a line with the word "say"

 

$contents = file_get_contents($file);

 

$pattern = preg_quote($searchfor, '/');

 

$pattern = "/^.*$pattern.*\$/m";

 

if(preg_match_all($pattern, $contents, $matches)){

  echo "<b>Chat:</b><br>";

  echo implode("<br>", $matches[0]);} //If found displays it.

 

else{

  echo "<b>Nobody said anything yet</b>"; } //If no one chatted

 

?>

 

Games_mp.log is updated by server in real time. There's other stuff in the file, so the above code filters out everything but the chat (say). It also displays the filtered results. What I want is (a.) have the chat lines limited to the last 10 or 20 lines in the file and (b.) have the text that's printed from games_mp.log refresh every second or less, without refreshing the page. Basically a live update on the php page, so I don't have to manually refresh the page. Also, is there a way to only print part of a line in the log file?  For example a sample chat line from games_mp.log would be

"39:23 say;01100001fdbfd223;3;Player 1;Hello Guys"

The first block of numbers is time, I don't really need that. the say lets me know they typed it. Dont need that, the next is the UID, don't need that, since this is just for chat. All I want diplayed on the php page is "Player 1;Hello Guys".

Hopefully this all makes sense, and I appreciate any response.

 

Link to comment
https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/
Share on other sites

Hello xps400mediacenter.

 

Phpaid is heading you in the right direction using AJAX, if you could maybes send me the full URL to the chat log file I could possibly come up with something for you, it won't be a fully fledged usable feature but I'll put the basics in there for you, then you can mess around with it to get it right :)

 

Regards, Paul.

Paul, thanks for the informative reply. At the moment, my webserver is down, and I don't have access to it. When it comes back online at ~4:00 CST, the address for the chat log is http://isnipeserver.dyndns-server.com/games_mp.log. I've also attached a log file for you to view in the meantime. Thanks again for your help.

 

[attachment deleted by admin]

Paul,

Thanks for the code. It looks really promising. Unfortunately, I'm extremely new to php, so I have no Idea what I'm doing. Is there things I need to fill in? Because right now, it's not displaying correctly . (http://isnipeserver.dyndns-server.com/chattest/chat.php) Sorry for being so bothersome, but I need more help.

 

Thanks :)

Try making the opening php flag a long flag.  Paul Ryan did the carnal sin and used short tags in the script.  A lot of servers have short tags set to OFF, therefore you will see the PHP code.

 

So, at the top of chat_messages.php find:

<?
//and change to:
<?php

 

And see if that helps.

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.