Jump to content

[SOLVED] reading character from lines from a file


Recommended Posts

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.

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

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>";

?>

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.