Jump to content

php find information in text file


adzie

Recommended Posts

Hello folks,

 

I'm trying to find a row in  a text file, so far I think I have been able to get the script to establish a row exists but I've been unable to retreive that row.

 

Any suggestions

 

$file = file_get_contents("test.txt");
$searchstrings = 'home';
$breakstrings = explode(',',$searchstrings);

foreach ($breakstrings as $values){
if(!strpos($file, $values)) {
    echo $values." string not found!\n";
  } else {
  echo $values." string Found!\n";
  }
}

 

The structure of the text file is the format below.

 

2009/07/30

Home 1 2 3 4 5 6

 

2009/07/31

Home 7 5 3 9 1 0

 

2009/08/01

Home 1 3 4 5 6 9

 

Link to comment
https://forums.phpfreaks.com/topic/168209-php-find-information-in-text-file/
Share on other sites

Hello folks,

 

I'm trying to find a row in  a text file, so far I think I have been able to get the script to establish a row exists but I've been unable to retreive that row.

 

Any suggestions

 

$file = file_get_contents("test.txt");
$searchstrings = 'home';
$breakstrings = explode(',',$searchstrings);

 

You are exploding $searchStrings which is equal to 'home'. I think you meant to do

explode($searchstrings,$file);

 

right?

Hi Lone Wolf,

 

I tried interpeting your idea, again similar result.

 

I'm sure its me.

 


<?php
$file = fopen("test.txt", "r") or exit("Unable to open file!");
  $string = 'home';
  if(stristr($string, 'home') == TRUE) {
    echo 'Record Found';

  }

fclose($file);

?>

 

 

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.