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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.