Jump to content

Insert HTML tags to text field entries before saving to text file


cdn

Recommended Posts

I have couple of issues that I like to get some help on. Any help would be appreciated

 

1a. What is the best format to save data - CSV or as plain text separated by "|". I need to display this data in another page later on. Let's call it display.html

 

1b. While I display the text in display.html page, I need to add some HTML formatting to the text, such as the entries from some of the textfield needs to be displayed as unordered list. User may be instructed to enter text int he text field seperated by comma or one item per line.

 

Is it better to add those tags before saving the entry to the text file or only when I read back that data later on to be displayed on the display.html page.

 

I prefer the second option, because then I can save the raw data and format the data with whichever tag I need for each page. Thats where I need the help. How do I read data from a file, and add html tags before displaying them.

 

Example

data.txt contents:

FR230E|Joe Smith|Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.|Philadelphia Arizona Ohio California

<repeated with similar data>

 

display.html should display the data as:

ID Number: FR230E

Name: Joe Smith

Description: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Cities Covered:

  • Philadelphia
  • Arizona
  • Ohio
  • California

 

Thank you. Please let me know if you need further clarification. Prefer a PHP solution.

 


// Put your data into an object...
$data = array();

$data[] = array('id'=>'FR23OE', 'name'=>'Joe Smith', 'desc'=>'A guy.');
$data[] = array('id'=>'FR23OF', 'name'=>'Joesph Smith', 'desc'=>'Another guy.');

// Later on, store it...
file_put_contents('dump.ser.gzs', gzcompress(serilize($data)));

// And retrieve it...
$data = unserilize(gzuncompress(file_get_contents('dump.ser.gzs')));

// And print with tags...
foreach($data as $record){
echo '<b>'.$record['id'].'</b>';
}

 

Boom!

 

or... you know, you could use databases like everyone else.

Hi Tiberrous,

 

Thank you for the reply. First of all, I don't have the option to use databases for this project and that is why I am stuck with having to use these round about ways.

 

1. I am assuming that you meant to write sterilize where you have written serilize in the code. And my understanding is that it is just to clean up the data before have it stored.

 

2. In the example, you have the data already stored in an array. In my case, I have to get the data using another form and have it saved in a text/csv file first. My first question was regarding whether it is better to save it as text file separated by | or is it better to save it as a CSV file.

 

3. Then, to display the data, I think I can use part of your code sample to open that file, read the contents to an array (which I like some help on - sample code).

 

4. The main question for me is how do I ADD html tags to a data, say to the data in the "desc" field to make the data in that field as an unordered list <ul><li></li></ul>, before having it displayed on the display page?

 

 

Any additional help would be greatly appreciated.

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.