Search the Community
Showing results for tags 'identify record in text files'.
-
Hello Larry, Thank you for your book that had helped me effectively changed my html website into php site - it's really clear and easy to learn from your book! I am now reaching the "Files and Directories" section (Chapter 11, page 297) and have gone through the chapter already. I was trying to write some code but was stuck here. I did some research on the web but still cannot make it. Could you please help? What I have been trying to do is to write a php script to do the following: 1) read the "First name" (or a unique "username") from the calling URL (using POST or GET), 2) then check the records in the text file to see if there is a match, 3) if there is a match, print the full name, company name and introduction of that record. I am enclosing a text file and my php script below for your review. The text file contains three lines (records), each line has the First name, Last name, Company name, Introduction. My script so far can only display all the elements of the file. I don't know how to pick only one record (line) from the file, then print elements of that record only. My question is: How could I identify a record in a text file (database), then print the selected values of that record only? I am not using a database program at this point. Thanks, Cofa Tsui New to the forum 9/4/2011 TEXT FILE 3 LINES ONLY "00_test_readtextfile_records.txt" ========================================= Peter##KWAN##First Street Company##This is my introduction. Please send me your comments. Thanks! Mary##THOMSON##Johnson High School##I am a grade 3 teacher here. I love facing the kids everyday! Billy##YU##Billy Travel Agency##We specialize in cruise ship tours in the Caribbean - Let me know when you'd like to have your vacation! PHP SCRIPT "00_test_readtextfile1.php" ========================================= <pre> <p>1ST PART - PRINT ALL LINES IN FILE ("config2" as array):</p> <?php $file = "00_test_readtextfile_records.txt"; $config = array(); $config1 = file_get_contents($file); $config2 = explode("\n",$config1); print_r($config2); ?> </pre> <br><br> <pre> <p>2ND PART - PRINT ELEMENTS OF INDIVIDUAL LINES</p> <?php $num; foreach ($config2 as $i) { $num++; } for ($i=0;$i<=$num-1;$i++) { $config3 = explode("##",$config2[$i]); print_r($config3); } ?> </pre>