Jump to content

Reading through file


stonebergftw

Recommended Posts

I have a problem that I don't know what to call.  It's simple I think.

 

I have file.txt .  In this file there are a lot of entries,some of which contain the string Goober######", where # is 1-infinite random character/s.

 

This string always ends with the character, ".  I need to go through file.txt and write each occurrence to an array.

 

Can someone help me with the syntax for this?

Link to comment
https://forums.phpfreaks.com/topic/241096-reading-through-file/
Share on other sites

Asuming the file looks something like this:

 

Goobergree098ge123"

Goober4gregregr56"

Goober78csgpouw59"

Goober0jl345312"

Goober34agro9szduvæl45"

Goober901gwradaegre"

Goober6jfiaoæryf89378"

 

then i would try:

 

<?PHP
$content = file('file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($content as $id => $line){
$tmp = explode('Goober',$line);	
$data[$id] = explode('"', $tmp[1], -1);
}
var_dump($data);
?>

 

which outputs an array

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.