Performs a case-insensitive search for words within a text file that contain, start with, or end with a specified substring.
The words list file should be a plaintext file with a single word per line.
To use, you must first include the search.list.php file within your project's code.
require "./php/search.list.php";
$ListSearch = new ListSearch();
You can then call the searchTextList() function to return an array of results containing a particular substring like so.
$listFileLocation = "./example/words.txt";
$substring = "xy";
// An array of results that contained "xy".
$resultArray = $ListSearch->searchTextList($listFileLocation, $substring);
Where
- $listFileLocation is the path to the file containing the list of words.
- $substring is the substring you're looking for within each of the words contained within the word list file.
You may also specify whether or not you'd like to limit results to words that either contain, start, or end with the substring.
// An array of results that contain the specified substring (default).
$resultArray = $ListSearch->searchTextList($listFileLocation, $substring, "contains");
// An array of results that start with the specified substring.
$resultArray = $ListSearch->searchTextList($listFileLocation, $substring, "starts");
// An array of results that end with the specified substring.
$resultArray = $ListSearch->searchTextList($listFileLocation, $substring, "ends");
- Mathew Norman - TheMathewNorman
This project is licensed under the MIT License - see the LICENSE file for details.