Intialise an array in PHP with default values

PHP has a useful function for initialising an array with default values called array_fill(). This post looks at how to use the array_fill function and the output of these arrays with the print_r function.

Categories PHP

Change the user agent string in PHP

Most of PHP’s file functions can be used to open local files as well as remote files via HTTP etc. By default the user agent string passed when making an HTTP requestis an empty string but it is possible in PHP to change the user agent string to something else. This post looks at how to do this.

Categories PHP

Return information from PHP print_r instead of displaying it

print_r is a useful PHP function for displaying the values of an array or object when debugging etc. Having been a PHP programmer since the days of PHP 3.x I didn’t realise this function had added the capability to return the information as well as print it from PHP 4.3.0 and only discovered this in the last few days. This post gives a brief overview of PHP’s print_r function.

Categories PHP

Work out if a number in PHP is odd or even

Sometimes you might need to know if a number is odd or even, and this post looks at how to determine if a number is odd or even in PHP using the modulus arithmetic operator.

Categories PHP

Update PHP from the command line with YUM

It is important to keep software up to date on your computer and web servers. I manage a few webservers which run Apache/PHP/MySQL on CentOS, a Red Hat Enterprise Linux derivitive, and use YUM to install software and keep it up to date. This post looks how you would just do an update to PHP using YUM on CentOS.

Categories PHP

Fix the mbstring PHP extension not found error in phpMyAdmin

phpMyAdmin is a web based front end to MySQL written in PHP. It likes to have the mbstring extension loaded if using a multi byte character set and will display warnings when you first log into phpMyAdmin if it is not available. This post looks at the error message and how to install the mbstring extension for PHP on CentOS / Red Hat Enterprise Linux using yum.

Categories PHP