Presentation is loading. Please wait.

Presentation is loading. Please wait.

Built-in Functions.

Similar presentations


Presentation on theme: "Built-in Functions."— Presentation transcript:

1 Built-in Functions

2 echo strrev("Hello world.");
Prints: .dlrow 0lleH

3 echo str_repeat("Hip ", 2);
Prints: Hip Hip

4 echo strtoupper("lowercase");
Prints: LOWERCASE

5 str_replace("text_to_find", "text_to_replace_it_with", name_of_string_to_work_on);
$strWord="abcdefg"; $strWord=str_replace("a","aa",$strWord); $strWord=str_replace("b","bb",$strWord); $strWord=str_replace("c","cc",$strWord); $strWord=str_replace("d","dd",$strWord); $strWord=str_replace("e","ee",$strWord); $strWord=str_replace("f","ff",$strWord); $strWord=str_replace("g","gg",$strWord); echo $strWord; Prints: aabbccddeeffgg

6 Good example: Formatting Output as Currency (Money)
Formatting Functions output text with formatting applied to it using special formatting characters Good example: Formatting Output as Currency (Money)

7 Time & Date Functions

8 checkdate(m, d, y) determines if the date specified by a month, day, and year really exists on the calendar. $valid=checkdate(13,1,1978); if($valid) echo "Real date"; else echo "Not real date";

9 mktime creates a timestamp for a given date and time. It takes as parameters the hour, minutes, seconds, month, day, and year. echo mktime(0,0,0,1,1,2000); //create timestamp for given date //number of hour 0-23 //number of minutes 0-59 //number of seconds 0-59 //number of month 1-12 //number of day 1-31 //year The timestamp, used alone, is, as you can see, not all that useful. You can, however use it along with another function called date.

10 Leave this off to use current date/time
Format: date($format, $timestamp); Example: $timestamp= mktime(0,0,0,1,1,2000); //create timestamp for given date echo date(SOME_FORMAT_YOU_SPECIFIED,$timestamp)."<br />"; Leave this off to use current date/time

11 Format Description Returned Value DAY SPECIFIERS d Day of month 2 digit, leading zeroes 01 to 31 D Day of week, three letters Mon to Sun j Day of month, no lead zeroes 1 to 31 l Day of week, full names Sunday to Saturday N Day of week, numeric, Monday to Sunday 1 to 7 S Suffix for day o fmonth st,nd, rd, or th w Day of week, numeric, Sunday to Sat 0 to 6 z Day of year 0 to 365 WEEK SPECIFIER W Week number of year 1 to 52 MONTH SPECIFIERS F Month name January to December m Month number with lead zeroes 01 to 12 M Month name, three letters Jan to Dec n Month number, no lead zeroes 1 to 12 t Number of days in given month 28, 29, 30, or 31 YEAR SPECIFIERS L Leap year 1=yes, 0=no Y Year, 4 digits 0000 to 9999 y Year, 2 digits 00 to 99 TIME SPECIFIERS a Before/after midday, lowercase am, pm A Before, after midday, uppercase AM, PM g Hour of day, 12-hr, no lead zeroes G Hour of day, 24-hr, no lead zeroes 1 to 24 h Hour of day, 12, lead zeroes H Hour of day, 24, lead zeroes 01 to 24 i Minutes with lead zeroes 00 to 59 s Seconds, with lead zeroes

12 $timestamp= mktime(6,0,0,7,14,1978); $format="D, F j, Y";
Example $timestamp= mktime(6,0,0,7,14,1978); $format="D, F j, Y"; echo "I was born " . date($format,$timestamp);

13 $right_now=date("L"); if($right_now==1) echo "This is a leap year"; else echo "This is not a leap year.";

14 More Info


Download ppt "Built-in Functions."

Similar presentations


Ads by Google