Php – Fix “Input is not proper UTF-8, indicate encoding” error when loading xml

By | March 26, 2013

When loading xml files in php through simplexml_load_string or domDocument class, sometimes an error like this might popup Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! OR Warning: simplexml_load_string(): Entity: line 93: parser error : Input is not proper UTF-8, indicate encoding ! The error occurs when the xml has some invalid characters… Read More »

Php – How to fetch gzipped content over HTTP with file_get_contents

By | January 13, 2023

The file_get_contents function is often used to quickly fetch a http url or resource. Usage is very simple and appears like this $content = file_get_contents('http://www.google.com/'); However the file_get_contents does not get the contents compressed. It requests the server to send everything in plain text format. Most websites are capable of serving compressed content, if they… Read More »

How to download a file using Curl in PHP – Code Snippet

By | January 13, 2023

Download a File using Curl Here is a quick curl snippet for php, that can download a remote file and save it. <?php set_time_limit(0); // File to save the contents to $fp = fopen ('files2.tar', 'w+'); $url = "http://localhost/files.tar"; // Here is the file we are downloading, replace spaces with %20 $ch = curl_init(str_replace(" ","%20",$url));… Read More »

How to extract tar.gz archives in Php

By | May 1, 2023

In a previous article we learned how to . Now lets do the reverse, that is extract tar.gz archives and get the files out. The code to extract a tar.gz archive is very simple and uses PharData class. Here is an example // decompress from gz $p = new PharData('files.tar.gz'); $p->decompress(); // creates files.tar //… Read More »

How to use proxy with curl in Php

By | May 1, 2023

Proxy with Curl Curl is a very useful library for transferring data over various protocols like http, ftp, https etc. In other words curl can be used to programatically download a web page, or upload file to ftp etc. It also supports using a proxy. This means that curl requests can go through a proxy… Read More »

Convert excel to csv in php

By | March 11, 2013

When working with data import and export for example, file formats like csv and excel are commonly used. Data can be exported to csv format and imported elsewhere. Also data might be entered manually in an excel file and then imported in the database. So there might be a need to convert excel files to… Read More »

Ajax based streaming and progress monitor

By | May 2, 2023

Streaming (Comet) Streaming means to send content part by part at some intervals in the same request. Or in other words, the client is able to process the response part by part, instead of waiting for the whole transfer to complete. In the context of http and web applications it is more specifically called Comet…. Read More »