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 »