Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ord, chunk_split, explode, and implode:
- a) ord():
- This function returns the ASCII value of the first character of a string.
- Example:
- $str = "Hello";
- echo ord($str); // Outputs: 72 (ASCII value of 'H')
- b) chunk_split():
- Splits a string into smaller chunks of a specified length.
- Example:
- $text = "HelloWorld";
- echo chunk_split($text, 3, "-");
- // Outputs: Hel-loW-orl-d-
- c) explode():
- Splits a string into an array by a specified delimiter.
- Example:
- $pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
- $pieces = explode(" ", $pizza);
- print_r($pieces);
- // Outputs: Array ( [0] => piece1 [1] => piece2 [2] => piece3 [3] => piece4 [4] => piece5 [5] => piece6 )
- d) implode():
- Joins array elements with a string.
- Example:
- $array = array('Hello', 'World', '!');
- echo implode(" ", $array);
- // Outputs: Hello World !
- mktime, strftime, strptime, and strtotime:
- a) mktime():
- Creates a Unix timestamp for a date.
- Example:
- echo mktime(10, 30, 0, 3, 15, 2023);
- // Outputs: 1678877400 (Unix timestamp for March 15, 2023, 10:30:00 AM)
- b) strftime():
- Formats a local time/date according to locale settings.
- Example:
- setlocale(LC_TIME, 'en_US');
- echo strftime("%B %d %Y, %X", mktime(20, 0, 0, 12, 31, 2023));
- // Outputs: December 31 2023, 20:00:00
- c) strptime():
- Parses a time/date generated with strftime().
- Example:
- $date = "2023-05-15 22:45:00";
- $parsed = strptime($date, "%Y-%m-%d %H:%M:%S");
- print_r($parsed);
- // Outputs an array with parsed date components
- d) strtotime():
- Parses an English textual datetime description into a Unix timestamp.
- Example:
- echo strtotime("now"), "\n";
- echo strtotime("10 September 2000"), "\n";
- echo strtotime("+1 day"), "\n";
- echo strtotime("+1 week"), "\n";
- echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
Advertisement
Add Comment
Please, Sign In to add comment