I recently bumped into an encoding issue on a project I was working on.
I was trying to scrape some content off a website that had ISO-8859-1 charset encoding, and I needed to capture some text and store it in a database as UTF-8.
After some trial and error I discovered a way to properly change the encoding before saving it in the DB.
A simplified version of what I did:
$url = 'http://www.smooka.com/blog/'; $html = file_get_contents($url); //Change encoding to UTF-8 from ISO-8859-1 $html = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $html);
Did you know that you can quickly change UTC time stamps to Local time by doing the following:
//make sure your time is set date_default_timezone_set('America/New_York'); $datetime = '2004-02-12T15:19:21+00:00'; //convert the given datetime string to time $newDatetime = strtotime($datetime); //re-contruct to format $newDatetime = date('Y-m-d H:i:s', newDatetime);
It’s so obvious, but I only wished, I knew this before trying all sort of crazy stuff.
If you want to unit test an action in a controller that checks the request to see if is an XML HTTP Request using the isXmlHttpRequest() method provided by the Zend Framework, then you will definitely run into a problem.
isXmlHttpRequest() pretty much checks to see if the $_SERVER[‘HTTP_X_REQUESTED_WITH’] is set with ‘XMLHttpRequest’, if not, then returns FALSE. I thought that by setting the server variable with XMLHttpRequest directly will allow me to bypass the check.
If you ever see the following message when trying to commit your code to a GIT repository.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
This week I set myself to lay the ground work of translation on the application we are doing at work. In our application we are using Zend Framework, so I decided to take a look into the Zend_Translate component to see if it was easy and something that could work in our current environment.
After reading the reference guide on Zend_Translate I decided that we were going to use “gettext” as our translation adapter. PHP has support for gettext right our of the box, and with the Zend_Translate it’s easy to change adapters, if you decide that you want to use a different adapter.
Assuming that you already have the latest version of Zend Framework (1.10.*) installed in your server, I’m going to explain and guide you guys on how I got it all working.