aakash2310

Untitled

Jul 31st, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. ord, chunk_split, explode, and implode:
  2.  
  3. a) ord():
  4. This function returns the ASCII value of the first character of a string.
  5. Example:
  6. $str = "Hello";
  7. echo ord($str); // Outputs: 72 (ASCII value of 'H')
  8. b) chunk_split():
  9. Splits a string into smaller chunks of a specified length.
  10. Example:
  11. $text = "HelloWorld";
  12. echo chunk_split($text, 3, "-");
  13. // Outputs: Hel-loW-orl-d-
  14. c) explode():
  15. Splits a string into an array by a specified delimiter.
  16. Example:
  17. $pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
  18. $pieces = explode(" ", $pizza);
  19. print_r($pieces);
  20. // Outputs: Array ( [0] => piece1 [1] => piece2 [2] => piece3 [3] => piece4 [4] => piece5 [5] => piece6 )
  21. d) implode():
  22. Joins array elements with a string.
  23. Example:
  24. $array = array('Hello', 'World', '!');
  25. echo implode(" ", $array);
  26. // Outputs: Hello World !
  27.  
  28. mktime, strftime, strptime, and strtotime:
  29.  
  30. a) mktime():
  31. Creates a Unix timestamp for a date.
  32. Example:
  33. echo mktime(10, 30, 0, 3, 15, 2023);
  34. // Outputs: 1678877400 (Unix timestamp for March 15, 2023, 10:30:00 AM)
  35. b) strftime():
  36. Formats a local time/date according to locale settings.
  37. Example:
  38. setlocale(LC_TIME, 'en_US');
  39. echo strftime("%B %d %Y, %X", mktime(20, 0, 0, 12, 31, 2023));
  40. // Outputs: December 31 2023, 20:00:00
  41. c) strptime():
  42. Parses a time/date generated with strftime().
  43. Example:
  44. $date = "2023-05-15 22:45:00";
  45. $parsed = strptime($date, "%Y-%m-%d %H:%M:%S");
  46. print_r($parsed);
  47. // Outputs an array with parsed date components
  48. d) strtotime():
  49. Parses an English textual datetime description into a Unix timestamp.
  50. Example:
  51. echo strtotime("now"), "\n";
  52. echo strtotime("10 September 2000"), "\n";
  53. echo strtotime("+1 day"), "\n";
  54. echo strtotime("+1 week"), "\n";
  55. echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
Advertisement
Add Comment
Please, Sign In to add comment