Jump to content

need help extracting content from a txt file on my computer


kevinkhan

Recommended Posts

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

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


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?

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

 

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.