kevinkhan Posted April 13, 2010 Share Posted April 13, 2010 Hi ya.. Im looking for some php logic to read all information from a number of txt files and put the information into a string so that i can parse emails and phone numbers out of the txt files.. the location of the txt files on my computer are here.. C:\Users\kevin\Documents\My Scans\scan0001.txt and i want to be able to put all the content of each txt file (no matter how many is there) into a string... The files are always named like this scan0001.txt scan0002.txt scan0003.txt etc... Hope some one can help Thanks Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 13, 2010 Share Posted April 13, 2010 try this $fole=file_get_contents('C:\\Users\\kevin\\Documents\\My Scans\\scan0001.txt'); echo $fole; Quote Link to comment Share on other sites More sharing options...
kevinkhan Posted April 13, 2010 Author Share Posted April 13, 2010 ok this worked but now im trying to extract all information in each of the files and put them into one variable... How would i go about setting up this array/loop? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 13, 2010 Share Posted April 13, 2010 try some thing like this $value="C:\\Users\\kevin\\Documents\\My Scans\\scan"; for($i=1;$i<=130;$i++) { if($i>=100) { echo $value.'0'.$i.".txt<br>"; } elseif($i>=10) { echo $value.'00'.$i.".txt<br>"; } else { echo $value.'000'.$i.".txt<br>"; } } Quote Link to comment Share on other sites More sharing options...
kevinkhan Posted April 13, 2010 Author Share Posted April 13, 2010 try some thing like this $value="C:\\Users\\kevin\\Documents\\My Scans\\scan"; for($i=1;$i<=130;$i++) { if($i>=100) { echo $value.'0'.$i.".txt<br>"; } elseif($i>=10) { echo $value.'00'.$i.".txt<br>"; } else { echo $value.'000'.$i.".txt<br>"; } } ok thats kind of cool.. but just as a matter of interest, what if there was only 2 files in the folder.. one was called scan0001.txt and the other was called scann0004.txt file.. how would this work then... and how do i put all the content of each of these files into a variable? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted April 13, 2010 Share Posted April 13, 2010 but just as a matter of interest, what if there was only 2 files in the folder.. one was called scan0001.txt and the other was called scann0004.txt file.. how would this work then... for this one i cannot do anything.. u have to check the files before.. and how do i put all the content of each of these files into a variable? for this what u need to do is that instead of echo use some thing like this $value="C:\\Users\\kevin\\Documents\\My Scans\\scan"; //echo $fole."<br>"; for($i=1;$i<=130;$i++) { if($i>=100) { $val1=$value.'0'.$i.".txt<br>"; $fole .= file_get_contents($val1); } elseif($i>=10) { $val2=$value.'00'.$i.".txt<br>"; $fole .= file_get_contents($val2); } else { $val3=$value.'000'.$i.".txt<br>"; $fole .= file_get_contents($val3); } } echo "File====><br> ".$fole; ?> 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.