Wednesday, 14 March 2012

Remove Inline NULL values from PHP arrays

Remove NULL values from PHP arrays with 1 line (Inline)
I had an array with something like the following: Array ( [0] => [1] => test [2] => fun ). But I don’t want [0], the empty value in the array.
After searching the web for a good solution, I saw that people were using anywhere from 4 to 10+ lines of code to remove null values from arrays. This is obviously overkill so I decided to tackle the problem myself.
Remove NULL values only
1
$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');
Remove any FALSE values
This includes NULL values, EMPTY arrays, etc. Thanks to Paul Scott for pointing out this method.
1
$new_array_without_nulls = array_filter($array_with_nulls);

Thursday, 1 September 2011

Split / Chunk / Capture complete words using substr() in PHP, limit by word

For [ How to capture complete words using substr() in PHP, limit by word? ]

$sub_words = explode('|', wordwrap(nl2br($m->Message), 50, '|')); 
echo $sub_words[0];

Thursday, 28 July 2011

Status of Amazon EC2 Server

To check the status of Amazon EC2 Server:
1
# tail -f /var/log/apache2/error.log

Cron Jobs at Amazon EC2 Server

Show you the list of cron jobs:
1
# crontab -l
It is a standard unix cron job file located in /var/www/project/_config/crontab.txt.

Tuesday, 17 May 2011

Difference between Function, Procedure and Stored Routine in MySQL

A quick summary:

A stored routine is either a procedure or a function.

A procedure is invoked using a CALL statement and can only pass back values using output variables.

A function can be called from inside a statement just like any other function and can return a scalar value.

reference: http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html

------------------------------------------------------------------------
Difference between Function, Procedure and Stored Routine in MySQL

Tuesday, 10 May 2011

Connecting to AWS EC2 (Linux) Instance With PuTTY via SSH In order to connect to an Amazon Web Services EC2 Linux instance using PuTTY over SSH you mu

Connecting to AWS EC2 (Linux) Instance With PuTTY via SSH
----------------------------------------------------------
In order to connect to an Amazon Web Services EC2 Linux instance using PuTTY over SSH you must generate a PPK file from your private key, then import the PPK to PuTTY. PuTTY does not natively support the private key format generated by Amazon EC2, therefore PuttyGen must be used to convert keys to its internal format.

please, download the following file with the complete information.

Connect to your Amazon AWS EC2 Linux machine using SSH and PuTTY in Windows

Monday, 9 May 2011

Checking IE Browser using PHP Script

Checking IE Browser using PHP Script
-------------------------------------
if (preg_match('|MSIE ([0-9].[0-9]{1,2})|',$_SERVER['HTTP_USER_AGENT'])) {
{
 echo 'IE';
}
else {
 echo 'Other Browser';
}