I have a notepad for php to read txt files based on conditions. content: & nbsp; articles. Theyareimmediatelyandpermanentlyavail php to read txt files based on conditions.
I now have a notepad with the following content:
Articles
The research articles in all journals published by BioPublisher are 'open access '. they are immediately and permanently available online without charge. A number of journals require an institutional or a personal subscribe to view other content, such as reviews or paper reports. free trial subscriptions to these journals are available.
About
Tel: *********************** address: *************************************
I now use PHP to read this notepad, because there is a good segment in it and there is a title before each segment. now I want to read different contents through the previous title.
Please advise.
------ Solution --------------------
The logic is incorrect. [email protected]
Modify as follows:
PHP code
"; Echo $ buffer ."
";} Else {echo" This is body
"; Echo $ buffer ."
";}} Fclose ($ fp); // close the file stream?>
------ Solution --------------------
[Email protected], separated by this. Note that @ should be the top level.
PHP code
$ Find = 'about'; // the title to be found $ file_name = "dir.txt"; $ fp = fopen ($ file_name, 'r'); $ title = ''; $ content = ''; while ($ buffer = fgets ($ fp, 1024) // The file does not have to be read {if ($ buffer {0} = '@') {// check whether the title is if ($ title = $ find) break; // if yes, exit $ title = trim ($ buffer ,'@'. PHP_EOL); // save the title $ content = ''; // clear the content} else $ content. = $ buffer; // save content} fclose ($ fp); // close the file stream echo content."
";
------ Solution --------------------
If the title is fixed, read a row and check whether the title is correct.
For example, the length of a line is less than one space.
------ Solution --------------------
Help top up ....