Jump to content

Recommended Posts

I need a way to hold some data in a file and when needed, echo a speific section of the file to my site.

Is there a way to do this?

 

example:

 

"dataholder.txt"

 

// this is the first section
I have some data here.
a bit more here.
// this is the seond section
this data is for another page on my site.

 

on the first page of my site I want to be able to echo the first section of "dataholder.txt", an on multiple other pages it should be the second section that gets echoed.

It perfectly possible, but you'd need some kind of delimiter to determine when one section starts and another begins. Can be anything really..

 

blah blah this is section 1

// NEW_SECTION

blah blah this is section 2

 

Then you can use explode() to explode the contents by "// NEW_SECTION" and echo out the right section.

 

A quick example:

 

<?php

$text = file_get_contents("dataholder.txt");
$sections = explode("// NEW_SECTION", $text);

echo $sections[0]; // section 1
echo $sections[1]; // section 2

?>

 

Adam

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.