index.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. // month() example
  104. $v = new DateTime("09/27/2021");
  105. echo(month($v)."&lt;br&gt;");
  106. </pre>
  107. <b>Result:</b><br>
  108. <?php
  109. $v = new DateTime("09/27/2021");
  110. echo(month($v)."<br><br>");
  111. ?>
  112. <pre style="width:500px">
  113. // day() example
  114. $v = new DateTime("09/27/2021");
  115. echo(day($v)."&lt;br&gt;");
  116. </pre>
  117. <b>Result:</b><br>
  118. <?php
  119. $v = new DateTime("09/27/2021");
  120. echo(day($v)."<br><br>");
  121. ?>
  122. <pre style="width:500px">
  123. // hour() example
  124. $v = new DateTime("09/27/2021 22:05:55");
  125. echo(hour($v)."&lt;br&gt;");
  126. </pre>
  127. <b>Result:</b><br>
  128. <?php
  129. $v = new DateTime("09/27/2021 22:05:55");
  130. echo(hour($v)."<br><br>");
  131. ?>
  132. <pre style="width:500px">
  133. // minute() example
  134. $v = new DateTime("09/27/2021 22:05:55");
  135. echo(minute($v)."&lt;br&gt;");
  136. </pre>
  137. <b>Result:</b><br>
  138. <?php
  139. $v = new DateTime("09/27/2021 22:05:55");
  140. echo(minute($v)."<br><br>");
  141. ?>
  142. <pre style="width:500px">
  143. // second() example
  144. $v = new DateTime("09/27/2021 22:05:55");
  145. echo(second($v)."&lt;br&gt;");
  146. </pre>
  147. <b>Result:</b><br>
  148. <?php
  149. $v = new DateTime("09/27/2021 22:05:55");
  150. echo(second($v)."<br><br>");
  151. ?>
  152. <pre style="width:500px">
  153. // monthName() example
  154. $v = new DateTime("09/27/2021 22:05:55");
  155. echo(monthName($v)."&lt;br&gt;");
  156. </pre>
  157. <b>Result:</b><br>
  158. <?php
  159. $v = new DateTime("09/27/2021 22:05:55");
  160. echo(monthName($v)."<br><br>");
  161. ?>
  162. <pre style="width:500px">
  163. // weekday() example
  164. $v = new DateTime("09/27/2021 22:05:55");
  165. echo(weekday($v)."&lt;br&gt;");
  166. </pre>
  167. <b>Result:</b><br>
  168. <?php
  169. $v = new DateTime("09/27/2021 22:05:55");
  170. echo(weekday($v)."<br><br>");
  171. ?>
  172. <pre style="width:500px">
  173. // now() example
  174. echo(now()."&lt;br&gt;");
  175. </pre>
  176. <b>Result:</b><br>
  177. <?php
  178. echo(now()."<br><br>");
  179. ?>
  180. <pre style="width:500px">
  181. // date_add1() example #1
  182. $d1 = new DateTime("09/27/2021 22:05:55");
  183. $d1 = date_add1("Y", 1, $d1);
  184. echo($d1->format("Y/d/m H:i:s A")."&lt;br&gt;");
  185. </pre>
  186. <b>Result:</b><br>
  187. <?php
  188. $d1 = new DateTime("09/27/2021 22:05:55");
  189. $d1 = date_add1("Y", 1, $d1);
  190. echo($d1->format("Y/d/m H:i:s A")."<br><br>");
  191. ?>