PHP tags
<?php ?>
Text Output
echo "something";
Variable
echo "something"; //$ in front, can not begin with a number, case sensitive
Constant
define("name", "value");
Format number
echo sprintf("%01.2f", 25); //25-->25.00
echo number_format(25000, 2); //25000-->25,000.00
Single-quoted Vs double-quoted strings
$age=12; $result1="age"; $result2='age'; //resut1:12 resutl2: $age
Joining string, or concatenation (dot . or .=). To get Hello World!
echo 'Hello'." ".'World';
Format a date ( August 10, 2006 –> 2006/08/10)
echo date("Y/m/d");
Array-Create. index starts with 0, use one of the following ways to create.
$pets[0]="unicorn"
$pets = array("dragon", "unicorn", "tiger");
$pets[] ="dragon"; $pets[] ="unicorn"; $pets[] ="tiger";
$capitals =array("CA" => "Sacramento", "TX" => "Austin", "OR" => "Salem" );
Array-Viewing.
print_r($pets);
var_dump($pets);
Array-Removing.
$pets[2]="";
unset ($pets[4]);
Array-Sorting.
sort("pets"); //To sort an array that has numbers as keys and reassign keys
asort("pets"); //To sort an array that has strings as keys
Array-Getting Values.
list ($firstvar, $secondvar)=$pets;
//To get value from an array that has numbers as keys and put them in variables
extract("pets");
//To copy all the values from an array into variables named from the corresponding keys. The sample from the book is wrong, since no key was assigned in $shirtInfo
current($arrayname) next($arrayname) previous($arrayname) end($arrayname) reset($arrayname);
//Manually iterate through an array
foreach($capitals as $state =>$city)
//walks through the array one value at a time.
Monthly Archives: November 2009
when you say nothing at all
One song by three singer. Interesting to see the differences. I first heard the song from the movie “Northing Hill” which was sung by Ronan Keating and still like it.
- Keith Whitley
- Alison Krauss
- Ronan Keating
whiskey lullaby
Sad song with beautiful voice from Alison Krauss and Brad Paisley. The video below is basically just lyrics floating. I did not like the “official” one, too much Hollywood, every one should have his/her own interpretation of why “She broke his heart”.
She put him out like the burnin’ end of a midnight cigarette
She broke his heart he spent his whole life tryin’ to forget
We watched him drink his pain away a little at a time
But he never could get drunk enough to get her off his mind
Until the night1st Chorus
He put that bottle to his head and pulled the trigger
And finally drank away her memory
Life is short but this time it was bigger
Than the strength he had to get up off his knees
We found him with his face down in the pillow
With a note that said I’ll love her till I die
And when we buried him beneath the willow
The angels sang a whiskey lullaby(Sing lullaby)
The rumors flew but nobody knew how much she blamed herself
For years and years she tried to hide the whiskey on her breath
She finally drank her pain away a little at a time
But she never could get drunk enough to get him off her mind
Until the night2nd Chorus
She put that bottle to her head and pulled the trigger
And finally drank away his memory
Life is short but this time it was bigger
Than the strength she had to get up off her knees
We found her with her face down in the pillow
Clinging to his picture for dear life
We laid her next to him beneath the willow
While the angels sang a whiskey lullaby