index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <?php
  2. /**
  3. * Copyright 2021, 2024 5 Mode
  4. *
  5. * This file is part of "PHP Classic ASP polyfills".
  6. *
  7. * "PHP Classic ASP polyfills" is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * "PHP Classic ASP polyfills" is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with "PHP Classic ASP polyfills". If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. * index.php
  21. *
  22. * PHP-Classic-ASP-polyfills index file.
  23. *
  24. * @author Daniele Bonini <my25mb@aol.com>
  25. * @copyrights (c) 2021, 2024, 5 Mode
  26. */
  27. define("FUNCTIONS_PATH", __DIR__.DIRECTORY_SEPARATOR."functions");
  28. // CLASSIC ASP POLYFILLS
  29. require FUNCTIONS_PATH . DIRECTORY_SEPARATOR . "/func.casp-datetime-polyfills.inc";
  30. require FUNCTIONS_PATH . DIRECTORY_SEPARATOR . "/func.casp-string-polyfills.inc";
  31. ?>
  32. <pre style="width:500px">
  33. // left() example
  34. $s = "Reputation is everything. Almost everything..";
  35. echo(left($s,10)."&lt;br&gt;");
  36. </pre>
  37. <b>Result:</b><br>
  38. <?php
  39. $s = "Reputation is everything. Almost everything..";
  40. echo(left($s,10)."<br><br>");
  41. ?>
  42. <pre style="width:500px">
  43. // right() example
  44. $s = "Reputation is everything. Almost everything..";
  45. echo(right($s,19)."&lt;br&gt;");
  46. </pre>
  47. <b>Result:</b><br>
  48. <?php
  49. $s = "Reputation is everything. Almost everything..";
  50. echo(right($s,19)."<br><br>");
  51. ?>
  52. <pre style="width:500px">
  53. // space() example
  54. $s = "Reputation is everything. Almost everything..";
  55. echo(left($s,10).space(5).right($s,35)."&lt;br&gt;");
  56. </pre>
  57. <b>Result:</b><br>
  58. <?php
  59. $s = "Reputation is everything. Almost everything..";
  60. echo(left($s,10).space(5).right($s,35)."<br><br>");
  61. ?>
  62. <pre style="width:500px">
  63. // id_date() example #1
  64. $s = "Reputation is everything. Almost everything..";
  65. echo((is_date($s)?"true":"false")."&lt;br&gt;");
  66. </pre>
  67. <b>Result:</b><br>
  68. <?php
  69. $s = "Reputation is everything. Almost everything..";
  70. echo((is_date($s)?"true":"false")."<br><br>");
  71. ?>
  72. <pre style="width:500px">
  73. // id_date() example #2
  74. $s = "27/09/2021";
  75. echo((is_date($s)?"true":"false")."&lt;br&gt;");
  76. </pre>
  77. <b>Result:</b><br>
  78. <?php
  79. $s = "27/09/2021";
  80. echo((is_date($s)?"true":"false")."<br><br>");
  81. ?>
  82. <pre style="width:500px">
  83. // year() example #1
  84. $v = "27/09/2021";
  85. echo(year($v)."&lt;br&gt;");
  86. </pre>
  87. <b>Result:</b><br>
  88. <?php
  89. $v = "09/27/2021";
  90. echo(year($v)."<br><br>");
  91. ?>
  92. <pre style="width:500px">
  93. // year() example #2
  94. $v = new DateTime("09/27/2021");
  95. echo(year($v)."&lt;br&gt;");
  96. </pre>
  97. <b>Result:</b><br>
  98. <?php
  99. $v = new DateTime("09/27/2021");
  100. echo(year($v)."<br><br>");
  101. ?>
  102. <pre style="width:500px">
  103. // year() example #3
  104. echo(year()."&lt;br&gt;");
  105. </pre>
  106. <b>Result:</b><br>
  107. <?php
  108. echo(year()."<br><br>");
  109. ?>
  110. <pre style="width:500px">
  111. // month() example
  112. $v = new DateTime("09/27/2021");
  113. echo(month($v)."&lt;br&gt;");
  114. </pre>
  115. <b>Result:</b><br>
  116. <?php
  117. $v = new DateTime("09/27/2021");
  118. echo(month($v)."<br><br>");
  119. ?>
  120. <pre style="width:500px">
  121. // day() example
  122. $v = new DateTime("09/27/2021");
  123. echo(day($v)."&lt;br&gt;");
  124. </pre>
  125. <b>Result:</b><br>
  126. <?php
  127. $v = new DateTime("09/27/2021");
  128. echo(day($v)."<br><br>");
  129. ?>
  130. <pre style="width:500px">
  131. // hour() example
  132. $v = new DateTime("09/27/2021 22:05:55");
  133. echo(hour($v)."&lt;br&gt;");
  134. </pre>
  135. <b>Result:</b><br>
  136. <?php
  137. $v = new DateTime("09/27/2021 22:05:55");
  138. echo(hour($v)."<br><br>");
  139. ?>
  140. <pre style="width:500px">
  141. // minute() example
  142. $v = new DateTime("09/27/2021 22:05:55");
  143. echo(minute($v)."&lt;br&gt;");
  144. </pre>
  145. <b>Result:</b><br>
  146. <?php
  147. $v = new DateTime("09/27/2021 22:05:55");
  148. echo(minute($v)."<br><br>");
  149. ?>
  150. <pre style="width:500px">
  151. // second() example
  152. $v = new DateTime("09/27/2021 22:05:55");
  153. echo(second($v)."&lt;br&gt;");
  154. </pre>
  155. <b>Result:</b><br>
  156. <?php
  157. $v = new DateTime("09/27/2021 22:05:55");
  158. echo(second($v)."<br><br>");
  159. ?>
  160. <pre style="width:500px">
  161. // monthName() example
  162. $v = new DateTime("09/27/2021 22:05:55");
  163. echo(monthName($v)."&lt;br&gt;");
  164. </pre>
  165. <b>Result:</b><br>
  166. <?php
  167. $v = new DateTime("09/27/2021 22:05:55");
  168. echo(monthName($v)."<br><br>");
  169. ?>
  170. <pre style="width:500px">
  171. // weekday() example
  172. $v = new DateTime("09/27/2021 22:05:55");
  173. echo(weekday($v)."&lt;br&gt;");
  174. </pre>
  175. <b>Result:</b><br>
  176. <?php
  177. $v = new DateTime("09/27/2021 22:05:55");
  178. echo(weekday($v)."<br><br>");
  179. ?>
  180. <pre style="width:500px">
  181. // now() example #1
  182. echo(now()."&lt;br&gt;");
  183. </pre>
  184. <b>Result:</b><br>
  185. <?php
  186. echo(now()."<br><br>");
  187. ?>
  188. <pre style="width:500px">
  189. // now() example #2
  190. $d = new DateTime(now());
  191. echo($d->format("m/d/Y g:i:s A")."&lt;br&gt;");
  192. </pre>
  193. <b>Result:</b><br>
  194. <?php
  195. $d = new DateTime(now());
  196. echo($d->format("m/d/Y g:i:s A")."<br><br>");
  197. ?>
  198. <pre style="width:500px">
  199. // date_add1() example #1
  200. $d = new DateTime("09/27/2021 22:05:55");
  201. $d = date_add1("Y", 1, $d);
  202. echo($d->format("Y/d/m g:i:s A")."&lt;br&gt;");
  203. </pre>
  204. <b>Result:</b><br>
  205. <?php
  206. $d = new DateTime("09/27/2021 22:05:55");
  207. $d = date_add1("Y", 1, $d);
  208. echo($d->format("Y/d/m g:i:s A")."<br><br>");
  209. ?>
  210. <pre style="width:500px">
  211. // date_add1() example #2
  212. $d = new DateTime("09/27/2021 22:05:55");
  213. $d = date_add1("d", -5, $d);
  214. echo($d->format("Y/d/m g:i:s A")."&lt;br&gt;");
  215. </pre>
  216. <b>Result:</b><br>
  217. <?php
  218. $d = new DateTime("09/27/2021 22:05:55");
  219. $d = date_add1("d", -5, $d);
  220. echo($d->format("Y/d/m g:i:s A")."<br><br>");
  221. ?>