Posts Categorized: php

Install PEAR modules on CentOS

Pear is used to fetch and install additional PHP packages from the Pear project. To use on CentOS first install Pear so we can run the pear binary: yum install php-pear Now pear is installed we can install the Net_MAC package – which can be used to discover the manufacturer from a Mac address: Example… Read more »

PHP Web Scraping for Munin

There is a web page created by someone else containing figures I would like to use to draw some graphs in Munin. The HTML in that page is a bit ugly and looks like: <TR ALIGN = “Center”> <TD ALIGN = “Left” WIDTH = “49%” BGCOLOR = “#ECECEC”> <B>Building</B> </TD> <TD ALIGN = “Center” WIDTH… Read more »

LAMP on Ubuntu

There are several different commands that can be used to install Apache and MySQL services with PHP support: sudo apt-get install tasksel && sudo tasksel sudo apt-get install lamp-server^ sudo apt-get install apache2 libapache2-mod-php5 php5 php5-cli php5-mysql php5-gd php5-mcrypt php5-curl mysql-client mysql-server libmysqlclient15-dev phpmyadmin   For number two the carat at the end is important.

PHP Ternary Operator for If Else

These two snippets of PHP perform the same function but the ternary operator takes much less space. Read more great PHP tips at

PHP Reporting Errors

To get PHP error reporting for a file or web application use one of the following methods:1. Add the following to the PHP code in the file: error_reporting(E_ALL);ini_set(‘display_errors’, ‘1’); 2. Add the following to a .htaccess file in the same directory: php_flag display_errors onphp_value error_reporting 2039 3. Edit the server php.ini file setting: display_errors =… Read more »

Printing Random Array Elements in PHP and Javascript

Non-dynamic tag cloud?  <script language=”JavaScript” type=”text/javascript”>                                var mytags = new Array(                                “histories”,”names”,                                “land”,”lists”,”free”                                );                                var randomseed=Math.floor(Math.random()*8)                                for(i=0;i<mytags.length;i++){                                        var randomnumber=Math.floor(Math.random()*141)                                        randomnumber=randomnumber+40;                                        if(randomnumber%randomseed!=0){                                        document.write(“<a style=’font-size:”+ randomnumber +”%;’>”+ mytags[i] + “</a> “);                                        }                                }                        </script> <?php$input = array(“histories”,”names”,                                “land”,”lists”,”free”);$rand_keys = array_rand($input, 30);for($i;$i<30;$i++){$randomnumber=rand(40,181);echo “<a style=’font-size:”.$randomnumber.”%;’>”.$input[$rand_keys[$i]] . “</a>\n”;}?>

PHP, Pear, PECL and UploadProgress

I had need to use the UploadProgress and SMTP Mail PECL PHP extensions so a brief overview: Check pear is installed and working: # which pear To get a list of help/commands: # pear help Run the updates: # pear channel-update Show the installed packages: # pear list This will install the Mail package… Read more »

PHP 5.2.0 Upgrade and Issues

In the official yum repositories for Red Hat/CentOS for RHEL5 / CentOS 5.1 the current version of PHP is (at time of writing) 5.1.6 however when trying to install the Magento e-commerce application required PHP version 5.2.0 or higher. To upgrade PHP to 5.2.5 I followed some instructions here on using the Remi repository i.e…. Read more »