The UberGallery is a very handy PHP tool to create image galleries. After the setup, it will automatically detect the image files in the folder and generate the thumbnail view on the webpage.
Tag Archives: PHP
PHP – Parse string into date and date comparison
// Get the date in string with Y-m-d format
$exp_date_s = "2013-04-22";
$today_s = date("Y-m-d");
// Convert the dates into timestamp
$exp_date = strtotime($exp_date_s);
$today = strtotime($today_s);
// Compare the timestamp
if ($exp_date > $today) {
// Not yet expired
} else {
// Expired
}
Done =)
Reference: Comparing Dates in PHP
PHP – String to DateTime and vice versa
// Assume you have a date string which is in d-m-Y format.
$date_string = '18-04-2013';
// Create the DateTime object
$date = date_create_from_format('d-m-Y', $date_string);
// Print the date in Y-m-d format.
print date('Y-m-d', $date->getTimestamp());
Done =)
Reference:
PHP – http:// wrapper is disabled in the server configuration by allow_url_fopen=0
If you find these 2 errors in the error log.
- …file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in…
- …failed to open stream: no suitable wrapper could be found in…
Edit the php.ini and enable the following 2 settings.
allow_url_fopen = On allow_url_include = On
Restart Apache and they should be fixed.
Done =)
Reference:
PHP – Write file in specific charset/encoding
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
CentOS – Install Alternative PHP Cache (APC)
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
PHP – Detect mobile device and do redirection
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
Ubuntu – Install PECL uploadprogress PHP extension on Nginx
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.
- apt-get install php5-dev
Drupal 7 – Pass values from PHP to Javascript
During Drupal development, sometimes we may need to manipulate some server data in Javascript. In this case, we could create a custom module to retrieve the database data and pass it to browser such that we can it it in Javascript.
1. Implement the hook_init().
function <module-name>_init() {
drupal_add_js(
array(
'eureka' => array( // we should use module name for best practice
'data' => array(
'Name' => 'ykyuen',
'Blog' => 'Eureka!',
'URL' => 'http://eureka.ykyuen.info/',
),
)
),
'setting'
);
}
Drupal 7 – Render a Block programmatically
Not long a ago, i have 2 posted about rendering Blocks and Views in PHP.
We can render the Drupal 7 block by PHP in another way.
Continue reading
