How can PHP be used to filter and display lines from a file based on a specific character, such as "="?
To filter and display lines from a file based on a specific character, such as "=", you can read the file line by line and use the strpos() function to check if the line contains the specific character. If the character is found, you can then display or process that line accordingly.
$file = fopen("example.txt", "r");
if ($file) {
while (($line = fgets($file)) !== false) {
if (strpos($line, "=") !== false) {
echo $line;
}
}
fclose($file);
} else {
echo "Error opening file.";
}
Related Questions
- Are there any potential syntax errors to be aware of when inserting the current date into a MySQL database column in PHP?
- How do PHP books compare to online resources like the PHP manual in terms of depth, clarity, and ease of learning for beginners?
- What are the advantages and disadvantages of using a full-text search in PHP compared to other search methods?