searching inside a file using php

Solutions on MaxInterview for searching inside a file using php by the best coders in the world

showing results for - "searching inside a file using php"
Greta
07 Nov 2018
1<?php
2$file = 'somefile.txt';
3$searchfor = 'name';
4
5// the following line prevents the browser from parsing this as HTML.
6header('Content-Type: text/plain');
7
8// get the file contents, assuming the file to be readable (and exist)
9$contents = file_get_contents($file);
10// escape special characters in the query
11$pattern = preg_quote($searchfor, '/');
12// finalise the regular expression, matching the whole line
13$pattern = "/^.*$pattern.*\$/m";
14// search, and store all matching occurences in $matches
15if(preg_match_all($pattern, $contents, $matches)){
16   echo "Found matches:\n";
17   echo implode("\n", $matches[0]);
18}
19else{
20   echo "No matches found";
21}
queries leading to this page
php search from filephp code to search in a textfilefind file and search word in phpphp search text in filephp how to search contact through txt filesearch from other file with file handling phpphp search filessearch files using phpsearch a file in phpsearch a string on a txt file in phpfind a text in all files phphow to search through a file using phpphp search for contact in txt filephp how to search through a text filephp search for file in directorysearch within all php filephp search string on a filephp search string in txt filefind in file phpphp grep in fileget txt file and search in that php php get file content patternphp search inside txt filesearch in file phpphp search in file for a stringphp grep filefind text in file phpphp search string in filesearch inside php filesfind value in file phpsearch for files phpfind string in txt file phphow to search for a word in a file using phphp search file in folderphp search in filesearching inside a file using phpsearch through txt list phpfind string in text file phpphp search in text filesphp file search 2a ifhow to search for a wors in text file phphow many lines is to match for php filehow to search insde txt file phpphp search filephp search value in filephp find specific value in txt filephp how to search txt file by namephp search txt filesearch text values from a php file phpphp search file for stringsearch from another file with file handling phpsearch in a file with phpget all text from a txt file that mathes a search phpphp search text filesearching inside a file using php