xps400mediacenter Posted December 3, 2010 Share Posted December 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/ Share on other sites More sharing options...
phpaid Posted December 3, 2010 Share Posted December 3, 2010 To do what you want you will need to do AJAX and use javascript. I have a good example on this site Ajax Shoutbox Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142524 Share on other sites More sharing options...
xps400mediacenter Posted December 3, 2010 Author Share Posted December 3, 2010 So there's no way do to any of what I want with PHP? The link you sent me is on the right track, but it don't want to save the chat anywhere. It's already in a file and I want it displayed in real time.. Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142623 Share on other sites More sharing options...
PaulRyan Posted December 3, 2010 Share Posted December 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142632 Share on other sites More sharing options...
xps400mediacenter Posted December 3, 2010 Author Share Posted December 3, 2010 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] Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142695 Share on other sites More sharing options...
PaulRyan Posted December 4, 2010 Share Posted December 4, 2010 Hey xps400mediacenter, I have some code for you Like I said it's basic but will put you on the right tracks, try it out tell me whatcha think. Regards, Paul. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142867 Share on other sites More sharing options...
xps400mediacenter Posted December 4, 2010 Author Share Posted December 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142961 Share on other sites More sharing options...
jcbones Posted December 4, 2010 Share Posted December 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142986 Share on other sites More sharing options...
xps400mediacenter Posted December 4, 2010 Author Share Posted December 4, 2010 Yes, Thanks so much. That was it. I remember now on my other php pages I needed <?php, I just thought the problem was something that I needed to add. Thanks again for your help Paul, much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/220528-viewing-ingame-chat-on-php-file/#findComment-1142993 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.