Alternative of PHP_Excel for Excel Reading and Writing

For Writing Excel

For Reading Excel

For Reading and Writing Excel

  • Ilia Alshanetsky’s Excel extension now on github (xls and xlsx, and requires business libXL segment)
  • spout OfficeOpenXML (xlsx) and CSV
  • PHP’s COM extension (requires a COM empowered spreadsheet program, for example, MS Excel or OpenOffice Calc running on the server)
  • SimpleExcel Claims to read and compose MS Excel XML/CSV/TSV/HTML/JSON/and so forth arranges

Another C++ Excel expansion for PHP, however you’ll have to manufacture it yourself, and the docs are really meager with regards to attempting to discover what usefulness (I can’t discover from the site what groups it bolsters, or whether it peruses or composes or both…. I’m speculating both) it offers is phpexcellib from SIMITGROUP.

All case to be quicker than PHPExcel from codeplex or from github, however (except for COM, PUNO Ilia’s wrapper around libXl and spout) they don’t offer both perusing and composing, or both xls and xlsx; might never again be upheld; and (while I haven’t tried Ilia’s expansion) just COM and PUNO offers the same level of control over the made exercise manual.

Source: http://stackoverflow.com/questions/3930975/alternative-for-php-excel

How to Get Response Headers Using file_get_contents in PHP

Learn how to retrieve HTTP response headers using file_get_contents() in PHP. A simple and lightweight alternative to cURL for inspecting headers.

When working with APIs or external resources in PHP, sometimes you need to inspect the HTTP response headers — not just the content. While cURL is commonly used for this, you can also retrieve headers using the built-in file_get_contents() function with the right stream context.

In this post, we learn the effective way to get response headers, while using PHP file_get_contents() function.

Using $http_response_header PHP variable to Get Response Headers

We use file_get_contents() to fetch the content from a URL. But with some configuration, you can also access the response headers.

Here’s how you can do it:

<?php
$url = "https://example.com";

// Create a stream context
$options = [
    "http" => [
        "method" => "GET",
        "header" => "User-Agent: PHP\r\n"
    ]
];
$context = stream_context_create($options);

// Fetch the content
$response = file_get_contents($url, false, $context);

// Display the content
echo $response;

// Get the response headers
print_r($http_response_header);
?>

Explanation

  • We used stream_context_create() to define HTTP request options, like headers or methods.
  • The $http_response_header is a special PHP variable automatically populated when using file_get_contents() with an HTTP context.
  • It contains the raw headers returned by the server as an indexed array.

Example Output

When you run the above script, $http_response_header might contain something like:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Content-Type: text/html; charset=UTF-8
    [2] => Date: Wed, 25 Jun 2025 10:30:00 GMT
    ...
)

Checking Specific Headers

You can loop through the headers to extract specific values:

foreach ($http_response_header as $header) {
    if (stripos($header, "Content-Type:") !== false) {
        echo "Content-Type Header: $header";
    }
}

Use Cases

We can use this method for various purpose as follows:

  • Verifying HTTP status codes
  • Checking content type or caching headers
  • Basic debugging of server responses without using cURL

Conclusion

While file_get_contents() is often seen as a simple way to read data from URLs, it’s surprisingly powerful when paired with stream contexts. For lightweight HTTP requests where you don’t need advanced control, it’s a quick alternative to cURL — and retrieving headers is straightforward using $http_response_header.