In PHP, what are some common methods or functions to use when extracting and manipulating data from specific lines and positions within a text file?

When extracting and manipulating data from specific lines and positions within a text file in PHP, common methods or functions to use include file() to read the file into an array, explode() to split each line into an array of values, and substr() to extract specific portions of the data based on character positions.

// Read the text file into an array
$lines = file('data.txt');

// Loop through each line and extract specific data
foreach ($lines as $line) {
    // Split the line into an array of values
    $values = explode(',', $line);
    
    // Extract data from specific positions using substr()
    $name = substr($values[0], 0, 10); // Extract first 10 characters
    $age = substr($values[1], 0, 2); // Extract first 2 characters
    
    // Manipulate and use the extracted data as needed
    echo "Name: $name, Age: $age\n";
}