Jump to content

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

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.