mccdave Posted January 18, 2008 Share Posted January 18, 2008 Hi I am very new to php and am trying to understand how to go about things... I am trying to diplay part of a .dat flatfile. After help on this board yesterday It now works. However the flatfile is written by a guestbook and enteries are displayed like this: 1200489731|Welcome |Hello and welcome to the website. I need to strip the number prior to the message and all | characters and if possible add : between the Welcome and the Hello I am using the following to display the first 10 words from the file: $lines = file('DATfiles/text.dat'); $firstLine = explode(' ', $lines[0]); $first10words = array_slice($firstLine, 0, 10); $string = implode(' ', $first10words); echo $string; Any pointers on how to go abou this would be great! Many thanks MCCDave Quote Link to comment https://forums.phpfreaks.com/topic/86631-removing-sections-of-flatfile-on-display/ Share on other sites More sharing options...
GingerRobot Posted January 18, 2008 Share Posted January 18, 2008 One way would be to explode by the pipe, and extract the relevant parts: <?php $lines = file('DATfiles/text.dat'); $firstLine = explode(' ', $lines[0]); $first10words = array_slice($firstLine, 0, 10); $string = implode(' ', $first10words); $parts = explode('|',$string); $message = $parts[1].' : '.$parts[2]; echo $message; ?> Quote Link to comment https://forums.phpfreaks.com/topic/86631-removing-sections-of-flatfile-on-display/#findComment-442679 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.