Jump to content

[SOLVED] get content from a file, and echo to site


warptwist

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

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.