You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.php 651B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. function starts_with($haystack, $needle)
  3. {
  4. return ($needle === ""
  5. || strrpos($haystack, $needle, -strlen($haystack)) !== false);
  6. }
  7. function ends_with($haystack, $needle)
  8. {
  9. return ($needle === ""
  10. || strpos($haystack, $needle, strlen($haystack) - strlen($needle))
  11. !== false);
  12. }
  13. function error($code, $message)
  14. {
  15. header("HTTP/ $code $message");
  16. die(json_encode(array("code" => intval($code), "message" => $message)));
  17. }
  18. function get_post($key, $is_error = true)
  19. {
  20. if (isset($_POST[$key]))
  21. return $_POST[$key];
  22. else if ($is_error)
  23. error(400, "Missing parameters");
  24. else
  25. return false;
  26. }
  27. ?>