Category Archives: Php Snippets

Php code snippets and examples

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 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 are asked to… Read More »

How to compress images in php using gd

By | March 12, 2013

Php applications might need to do some image processing if they are allowing users to upload pictures of somekind. This can include cropping, watermarking, compressing etc. To compress an image the quality needs to be adjusted. Here are few examples The above function will process a jpg/gif/png image and compress it and save to jpg… Read More »