Answers for "search string in txt file in php"

PHP
1

php get all txt files in directory

$path = '/path/to/directory';
$files = glob($path."/*.txt");
foreach ($files as $file) {
  echo $file;
  echo '<br>';
}
/* Outputs something like: 
	/path/to/directory/someFile.txt
	/path/to/directory/someOtherFile.txt
	/path/to/directory/anotherFile.txt
*/
Posted by: Guest on July-24-2021
1

get values from text file php

$lines_array = file("file.txt");
$search_string = "bing";

foreach($lines_array as $line) {
    if(strpos($line, $search_string) !== false) {
        list(, $new_str) = explode(":", $line);
        // If you don't want the space before the word bong, uncomment the following line.
        //$new_str = trim($new_str);
    }
}

echo $new_str;

?>
Posted by: Guest on December-18-2021

Browse Popular Code Answers by Language