Category Archives: Coding

All kinds of Programming.

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 – Fetch gzipped content over http with file_get_contents

By | March 24, 2013

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(‘’); 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 »

Parse the user agent with ua-parser in php – detect browser, os and device

By | March 22, 2013

In your web application you might need to parse the user’s user-agent string to find out the browser/OS/device being used. This is necessary specially when your webapp tries to adapt to the user’s platform in a better way. For example a different layout for mobile device or restricted features/graceful degradation on a non supporting browser…. Read More »

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

By | March 19, 2013

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 »

Get the path of tmpfile in php

By | March 14, 2013

tmpfile is a very handy function to create temporary files. It returns the file handle/resource. If the path of the file is needed, for use with file_put_contents for example then here is a quick trick to do that $path = array_search(‘uri’, @array_flip(stream_get_meta_data($GLOBALS[mt_rand()]=tmpfile()))); file_put_contents($path, ‘hello’); echo file_get_contents($path); Last Updated On : 14th March 2013