This is the code
<?php
function findSubstringInFile($filePath, $substring) {
// Open the file in read mode
$fileHandle = fopen($filePath, "r");
if (!$fileHandle) {
die("Unable to open file!");
}
// Iterate through each line of the file
while (($line = fgets($fileHandle)) !== false) {
// Check if the substring is present in the current line
if (strpos($substring, rtrim($line, "rn")) !== false) {
// If substring is found, print the line
echo "Found: " . $line;
echo "<br>";
}
}
// Close the file handle
fclose($fileHandle);
}
// Example usage
$filePath = "database.txt";
$substring = file_get_contents("86400.txt");
findSubstringInFile($filePath, $substring);
?>
Here,
- database.txt is 2.1 GB. So, there are so many lines.
- Also a 86400.txt file which has 8600 lines data
Aim: I want to get matched line or common lines between database.txt and 86400.txt. My code works well when 86400.txt contains less lines. But for 86400 lines is there any solution?