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 Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/ 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; Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/#findComment-1040861 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? Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/#findComment-1040863 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>"; } } Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/#findComment-1040882 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? Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/#findComment-1040892 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; ?> Link to comment https://forums.phpfreaks.com/topic/198364-need-help-extracting-content-from-a-txt-file-on-my-computer/#findComment-1040897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.