![php find word in file php find word in file](https://www.kindacode.com/wp-content/uploads/2020/10/Screen-Shot-2020-10-11-at-16.58.15.jpg)
enter any text and hit on submit button and check your data.txt file. By default, grep displays the matched lines, and it can be used to search for lines of text that match one or more regular expressions, and it outputs only the matched lines. create a new file in the same directory or folder & name it data.txt and save it. Step 3: Now counts the number of word in a string using substr. The grep command is primarily used to search a text or file for lines that contain a match to the specified words/strings. Step 2: Convert the multiple white spaces into single space using the substrcount () and strreplace () method. Step 1: Remove the trailing and leading white spaces using the trim () method.
![php find word in file php find word in file](https://www.ryadel.com/wp-content/uploads/2016/05/Microsoft-Word-2013-Logo-Web1.jpg)