PHP Intro

basic loops in PHP

February 10, 2013

Loops execute a block of code a specified number of times, or while a specified condition is true. for for ($i = 1; $i $mon) { echo $key . " – " . $mon . ""; } output: 0 – January 1 – February … 11 – December $characters = "Porky Pig"; $characters = "Daffy Duck"; $characters = "Speedy Gonzales"; foreach ($characters as $key...

Read more »

PHP INTRO, debugging, html quotes, closing tags, security

December 12, 2012

updated 2014-07-25 PHP is perhaps the most widely-used general-purpose scripting language*, especially suited for Web development. It is, in fact, the programming component of the "LAMP" environment: Linux, Apache, MySql, Php. PHP is surprisingly more popular than Microsoft’s own ASP web scripting language! PHP runs lot faster than ASP on MS Windows and has more features and functionalities than Microsoft ASP. PHP is much...

Read more »

php, Arrays

March 12, 2012

updated 2016-04-09 Array keys start from 0, not 1. In an associative array a key is associated with a value. An array in PHP is actually an ordered map. (each key is mapped to a value). array values can be other arrays, trees and multidimensional arrays are also possible. A value can be any PHP type. A key may be either an integer or...

Read more »

PHP: Writing your own functions

December 16, 2011

"All custom functions should start with xxx_ so that the developer knows a native PHP function is not being called.* where xxx == your initials, or the project’s initials, or …" An example custom function style: function pwb_my_function($parameter1, $parameter2) { global $an_outside_variable; .... return true; } functions with optional parameters suppose you are using a function with 1 param, and in some new cases,...

Read more »

php basic String functions

November 10, 2010

updated 2014-08-07 strcmp, substring, strtoupper, strtolower, str_replace, addslashes, trim, strstr, strpos, str_repeat, strrev, explode, implode, chunk_split, . . .   string length $length = strlen($str); substring $str = "abcdefgh"; echo substr($str, 1); // bcdefgh echo substr($str, 3); // defgh echo substr($str, -1); // h echo substr($str, 2, 4); // cdef (starting point, length)   compare If you need to compare two strings, the strcmp()...

Read more »

Syntax Check a PHP Pgm

May 14, 2010

Be sure your error reporting is turned on: (for your testing copy or for your IP address) @ini_set('display_errors', '1'); error_reporting(E_ALL ^ E_NOTICE); If it is and you still get nothing but a blank page … then, by all means, your next step might be to take the syntax check option built into PHP! From a linux/unix command line (terminal session), run php with its...

Read more »

php Number Formatting, Rounding, and Incrementing

February 10, 2010

Rounding "The round() function rounds the number passed in to the specified number of decimal places. If the decimal places is a negative number then the numbers to the left of the decimal place are rounded. If the decimal places parameter is not passed in then it defaults to zero and will round as an integer. 5 is round up and < 5 is...

Read more »