How can a specific line be read from a text file in PHP?
To read a specific line from a text file in PHP, you can use the `file()` function to read the entire file into an array and then access the desired line by its index. You can specify the line number you want to read and subtract 1 from it to get the correct index in the array.
$lines = file('file.txt');
$lineNumber = 3; // specify the line number you want to read
$desiredLine = $lines[$lineNumber - 1];
echo $desiredLine;
Keywords
Related Questions
- What role does the .htaccess file play in redirecting HTTP requests to HTTPS, and how does this impact form submissions in PHP?
- How can beginners avoid common mistakes when implementing encryption and decryption functionality in PHP using mcrypt()?
- How do popular forum platforms like PHPBB handle displaying online users, and can this be replicated in custom PHP scripts?