bluebutterflyofyourmind Posted October 21, 2007 Share Posted October 21, 2007 hey there. I'm using file() to create an array of the lines from a .txt file. I guess i have two questions. 1) how to I refer to each line individually after the array is created. ie. do action A to line 5. 2) how would I search through that line in order to fine a specific character. ex. 1 Product Name: Macromedia Director MX 2004 Bible so I want to loop through to ':' so I can cut of that part of the line and then display the rest of the line. thanks for any help. Link to comment https://forums.phpfreaks.com/topic/74149-solved-reading-character-from-lines-from-a-file/ Share on other sites More sharing options...
tibberous Posted October 21, 2007 Share Posted October 21, 2007 file returns an array. So, to get to the 5th line, you would do: $lines = file('filename'); echo $lines[4]; // the 5th line To go through each item, use a foreach loop, to get the part after the :, use the explode function. Link to comment https://forums.phpfreaks.com/topic/74149-solved-reading-character-from-lines-from-a-file/#findComment-374483 Share on other sites More sharing options...
bluebutterflyofyourmind Posted October 21, 2007 Author Share Posted October 21, 2007 so that was very helpful but now i'm still running into a problem. I print the specific line of the array just fine but when i use the explode function, it just prints the word "Array". $filearray = file("ProductInfo.txt"); echo $filearray[2],"<BR>"; $portion = explode(":", $filearray[2]); echo $portion,"<BR><BR>"; that's the code i have so far Link to comment https://forums.phpfreaks.com/topic/74149-solved-reading-character-from-lines-from-a-file/#findComment-374518 Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 It's because your missing the bracket parts when you use $portion. I don' know how your not getting a syntax error using commas for concating. <?php $filearray = file("ProductInfo.txt"); echo $filearray[2]."<BR>"; $portion = explode(":", $filearray[2]); echo $portion[1]."<BR><BR>"; ?> Link to comment https://forums.phpfreaks.com/topic/74149-solved-reading-character-from-lines-from-a-file/#findComment-374521 Share on other sites More sharing options...
bluebutterflyofyourmind Posted October 21, 2007 Author Share Posted October 21, 2007 wow that makes me sooo happy that works. thanks a lot for your help. ya i'm kinda new to php. for some reason the comma's have been working pretty well. buut they're al changed to periods now that i know better. thanks again! Link to comment https://forums.phpfreaks.com/topic/74149-solved-reading-character-from-lines-from-a-file/#findComment-374522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.