get variable from flat file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arctushar
Forum Newbie
Posts: 5
Joined: Mon Aug 31, 2009 10:48 am

get variable from flat file

Post by arctushar »

Hello
I m not so advanced in php. I m new in php. I have a flat file named "data".
In the file "data" content is as below

$a=The$b=quick$c=brown

Now I want that a file will get variable data from the file
Say get data of variable $b so that I can output "quick" as echo

How can I do that plz help me
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: get variable from flat file

Post by califdon »

You can read a text file with fopen() and fread(). Then you would have to parse the data to separate the data. If you have any choice about how it is formatted, you should insert a special character, such as the "pipe" (|) character, between different data, making it easier to separate (see explode()). There are better ways to handle the storage of data, even without using a database, depending on what it is that you are trying to do.
arctushar
Forum Newbie
Posts: 5
Joined: Mon Aug 31, 2009 10:48 am

Re: get variable from flat file

Post by arctushar »

Thanks for ur reply. but isn't there any simple function where i can direct get variable. I meen just find the variable (eg.$b) and output the data?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: get variable from flat file

Post by califdon »

arctushar wrote:Thanks for ur reply. but isn't there any simple function where i can direct get variable. I meen just find the variable (eg.$b) and output the data?
It's not a variable until you create the variable in PHP. In a text file, it is simply some ASCII characters. If you have control of the file, you could make it a PHP file, then just include() it in your other file, but if you receive the file from somewhere out of your control, you can only treat it as characters in a file.
Post Reply