php

Add HTML5 Audio to Drupal's Audio Module (for iPad for instance)

Recently, My father got an iPad; it's his one internet-enabled device. He mentioned that he couldn't listen to any of the audio on my site. Well, I found this to be unacceptable, and, while we still on the phone, I made the following changes to Drupal's Audio Module:

1. Add a class and title to the flash player.

FIrst, edit the "1pixelout.inc" file in the audio/players/ directory (or edit the .inc file for the play you have chosen to use.) Add the following class to the flash object tag: class="1pixelflashplayer". Also, add the following title attribute to the object tag: title="{$options['soundFile']}".

2. Add javascript to the page

The following javascript will search for all the flash players with the aforementioned class, hide them, and insert an <audio> tag after them with the src of the video from the flash player. Note: This will only work for mp3 audio files. You can download the javascript at the bottom of the page.

I Hope this helps someone.  Javascript follows...

Normailze phone numbers using regex in PHP

Recently, it became necessary to normalize phone numbers for my work on SimpleChurchCRM. In order to normalize something, we must first understand it and analyze it.

The following regular expression will match phone numbers and their parts.

([(]?(?P<area>\d{3})[)]?)?(?: ?-?)?(?P<three>\d{3})(?: ?-?)?(?P<four>\d{4})( (x|(ext\.? ))(?P<ext>\d+))?

Note that this requires PHP > 5.2.2 I think. 

PHP's mysql_connect Function Anomalie

Recently, when trying to make 2 similtanious connections to the same mysql server with different databases, I noticed that this is not strictly possible without a little tweak.

The following will not work as expected:

$con1 = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('db1', $con1);

$con2 = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('db2', $con2);