What are the differences in handling hyperlinks between Excel and CSV files when reading data with PHP?

When reading data from an Excel file using PHP, hyperlinks are typically preserved as clickable links. However, when reading data from a CSV file, hyperlinks are usually treated as plain text. To handle hyperlinks from CSV files in the same way as Excel files, you can use the PHPExcel library to read the CSV file and extract the hyperlink information.

// Include PHPExcel library
require_once 'PHPExcel/PHPExcel.php';

// Load the CSV file
$inputFileName = 'example.csv';
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);

// Get the active sheet
$sheet = $objPHPExcel->getActiveSheet();

// Iterate through each row and column to extract hyperlink information
foreach ($sheet->getRowIterator() as $row) {
    foreach ($row->getCellIterator() as $cell) {
        $hyperlink = $cell->getHyperlink();
        if ($hyperlink) {
            echo 'Hyperlink URL: ' . $hyperlink->getUrl() . '<br>';
            echo 'Hyperlink Label: ' . $cell->getValue() . '<br>';
        }
    }
}