Jump to content

removing sections of flatfile on display


mccdave

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/86631-removing-sections-of-flatfile-on-display/
Share on other sites

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;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.