cdn Posted July 30, 2008 Share Posted July 30, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117439-insert-html-tags-to-text-field-entries-before-saving-to-text-file/ Share on other sites More sharing options...
cdn Posted July 31, 2008 Author Share Posted July 31, 2008 Can anyone help please.... this is probably two liner PHP code for an expert.... or any suggestions as to how to add tags to a text field entry as they are read from a file, that would be helpful. Link to comment https://forums.phpfreaks.com/topic/117439-insert-html-tags-to-text-field-entries-before-saving-to-text-file/#findComment-604231 Share on other sites More sharing options...
tibberous Posted July 31, 2008 Share Posted July 31, 2008 Use gzipped sterilized objects. You can do everything you want to with no screwing around. Link to comment https://forums.phpfreaks.com/topic/117439-insert-html-tags-to-text-field-entries-before-saving-to-text-file/#findComment-604238 Share on other sites More sharing options...
tibberous Posted July 31, 2008 Share Posted July 31, 2008 // 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. Link to comment https://forums.phpfreaks.com/topic/117439-insert-html-tags-to-text-field-entries-before-saving-to-text-file/#findComment-604240 Share on other sites More sharing options...
cdn Posted August 6, 2008 Author Share Posted August 6, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117439-insert-html-tags-to-text-field-entries-before-saving-to-text-file/#findComment-609832 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.