wverbist Posted October 8, 2007 Share Posted October 8, 2007 Hi. I am new to PHP development and I am working on a very small project right now that I thought would be the perfect place for me to dive in and learn. So far, so good but the question I have is about importing a .txt file. I have the file importing properly and the CSS is applying properly but what I want to know is how to have a single .txt but attach variables to certain lines to just pull data from that section. This is hard to describe so here is the link to the page that I am working on: http://www.williamverbist.com/_ethno/ethnic_spring.php The area I am referring to is the Title(s) and product description. Is there a way that all of that data can be in a single text file but by adding varibles or arrays to lines that when you click on one of the circles to see another product that the copy area will change as well? I work a lot in Flash and have done that there many times but was not sure if it is possible with just PHP or do I actually need to build a small MySQL database? Since there will not be a ton of data here, I was trying to keep this as simple as possible. Any help would be appreciated. Thanks. wverbist is offline Reply With Quote Quote Link to comment Share on other sites More sharing options...
Fadion Posted October 8, 2007 Share Posted October 8, 2007 In flash u can use loadVariables() but not in php. Im not sure how u want to achieve this, but im thinking that including a php file that contains the variables isnt your case. To open a text file u can use fopen() combined with fread() or fgets(), or file_get_contents() or just file(). I usually find it better using fopen() and loop through all the lines with fgets(). Actually ull need to scan through all the lines of the opened text file and search for a specified variable. If u find it, get its value. Consider this simple example: Text File $title = Some jewels $price = 1500 <?php $handle = fopen('file.txt', 'r'); while(!feof($handle)){ $line = fgets($handle, 4096); if(strstr($line, '$title')){ $title = substr(strrchr($line, '='), 1); } elseif(strstr($line, '$price')){ $price = intval(substr(strrchr($line, '='), 1); } } ?> Probably there's a simpler method, but this is what i got. Hope it helped to get the idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.