# \[PHP\] Reading Text from file

**URL:** <https://forum.kirupa.com/t/php-reading-text-from-file/179214>\
**Category:** Uncategorized\
**Created:** [February 17, 2006, 6:18pm UTC](https://forum.kirupa.com/t/php-reading-text-from-file/179214 "2006-02-17T18:18:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunk](https://avatars.discourse-cdn.com/v4/letter/c/ee59a6/32.png) [@chunk](https://forum.kirupa.com/u/chunk)\
**Post date:** [February 17, 2006, 6:18pm UTC](https://forum.kirupa.com/t/php-reading-text-from-file/179214/1 "2006-02-17T18:18:06Z")

</div>

Hi, I really don’t know how to go about this problem: :ne:

I have a .txt file formatted like this:

Fruit  
Apple pear orange etc…

Vegitable  
Carrot Pea etc…

(the space indicates set of details)

How would I go about it, so when the user selects “Fruit” the PHP file looks for the word Fruit, and takes the next line and puts it into the veriable $a or somthing.

I think it would use some kind of, Foreach(); command but I don’t know how it would only take out the next line and put that into a variable.

thanks for all your help 🙂
