Page 150 - Open Soource Technologies 304.indd
P. 150
Unit 8: Working with Strings, Date and Time
$placeholders = array(‘offspring’, ‘pronoun’, ‘pronoun2’, ‘sex’); Notes
//male replace values array
$malevals = array(‘son’, ‘he’, ‘him’, ‘boy’);
//female replace values array
$malevals = array(‘son’, ‘he’, ‘him’, ‘boy’);
//female replace values array
$femalevals = array(‘daughter’, ‘she’, ‘her’, ‘girl’);
//male string
$malestr = str_replace($placeholders, $malevals, $rawstring);
//female string
$femalestr = str_replace($placeholders, $femalevals, $rawstring);
echo “Son: “. $malestr . “<br />”;
echo “Daughter:“. $femalestr;
Output:
Son: Welcome Birmingham parent!
Your son is a pleasure to have! We believe he is learning a lot.
The faculty simple adores he2 and you can often hear them say “Attah boy!”
Daughter: Welcome Birmingham parent!
Your daughter is a pleasure to have! We believe she is learning a lot.
The faculty simple adores she2 and you can often hear them say “Attah girl!”
8.9 Summary
• PHP has a range of functions that handle date and time. Some of these functions work
with a so-called Unix timestamp, which is the number of seconds since January 1, 1970
at 00:00:00 GMT.
• The easiest way of obtaining the current time is with the time( ) function.
• The opposite of formatting text is parsing a textual description of a date into a timestamp.
The strtotime() function handles many different formats.
• Strings in PHP are a sequence of characters that are always internally null terminated.
• Individual characters in a string can be accessed using the $str{offset} notation.
LOVELY PROFESSIONAL UNIVERSITY 145