Sometimes we need to specify the file charset before writing the data to a file. The data strings which we get from the database are in UTF-8 so we have to convert them in proper charset. This could be done be iconv().
For example, i want to write the Traditional Chinese in Big5. The conversion could be done by.
Continue reading PHP – Write file in specific charset/encoding
Haven’t worked with CentOS for a long time. Miss the time and the teammates in HKU CECID.
Here are the steps to install Alternative PHP Cache (APC) on CentOS.
1. Install the following packages.
yum install php-pear php-devel httpd-devel pcre-devel gcc make
Continue reading CentOS – Install Alternative PHP Cache (APC)
We can use PHP to detect the browser user agent such that it would redirect user to another URL if the request comes from a mobile device.
1. Create the user_agent.php.
Continue reading PHP – Detect mobile device and do redirection
In Drupal, we can use a progress bar when uploading an image or file. But that needs a PHP PECL extension called uploadprogress. The following steps work for Ubuntu Precise (Ubuntu 12.04.1 LTS).
1. Install the php5-dev package.
Continue reading Ubuntu – Install PECL uploadprogress PHP extension on Nginx
Previous: Ubuntu – Install APC with PHP-FPM and Nginx
Memcached is a distributed memory caching system and it caches data and objects in RAM to reduce the number of times an external data source (such as a database or API) must be read.
Like APC, the installation is simple.
1. Install Memcached.
- apt-get install memcached
Continue reading Ubuntu – Install Memcached with PHP-FPM and Nginx
Next: Ubuntu – Install Memcached with PHP-FPM and Nginx
APC stands for Alternative PHP Cache is a opcode which also known as machine code. The opcode is cached such that every time a request is sent to server, the same opcode is used until it detects a change in the PHP file.
Installation is easy and straight forward.
1. Install using apt-get.
Continue reading Ubuntu – Install APC with PHP-FPM and Nginx
Update @ 2013-05-09: I am not very sure if this could really enable the Nginx Microcaching as i couldn’t find the HIT value in the HTTP response. Please feel free to comment and let us know if you got the solution. Thanks. =D
Enable Microcaching in Nginx could help making your website run much faster. Base on the setting we did in Nginx + PHP-FPM on Ubuntu Precise. Let’s edit the VirtualHost configuration file to enable Microcaching.
Continue reading Nginx – Enable Microcaching
Previous post: Nginx – Installation on Ubuntu Precise
Most of the time we would like to run PHP on our web server. After you have installed Nginx following the post above. We can now enable PHP.
1. Install the PHP packages.
apt-get install php5-fpm
apt-get install php5-cli
apt-get install php5-gd
apt-get install php-pear
Continue reading Nginx + PHP-FPM on Ubuntu Precise
I am working on a Hotel Booking website. The booking feature is provided by Hotel Booking System for Ubercart. But this module is not actively maintained so there are some bugs which i have to fix it for myself.
One of the bug is about strtotime(‘+1 month’). Intuitively, you may think you could get a date of next month. But here comes the problem. Assume you are now on 31st Jan. Since February only has 28 days (sometimes 29), strtotime(‘+1 month’) will return 3rd Mar.
Continue reading PHP – Get the next month by strtotime
About one and a half year ago, i published a blog post about adding text to image in PHP.
PHP – Add Text on an Image
The above example only display the image in browser, but it would not save the image on the server. Today i would like to show you another example which could save the image with text added on server.
What you need is 3 files.
- kenshin.jpg (The image which you wanna add text on it)
- arial.ttf (Or any other .ttf font file)
Continue reading PHP – Add text on an image with background color and save it on the server