]> 91.132.146.200 Git - dolphin.git/commitdiff
added startswith and endswith
authorBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:33:46 +0000 (15:33 +0200)
committerBanana <banana@optimus.de>
Tue, 16 Jul 2019 13:33:46 +0000 (15:33 +0200)
single-functions/endswith.php [new file with mode: 0644]
single-functions/starts-with.php [new file with mode: 0644]

diff --git a/single-functions/endswith.php b/single-functions/endswith.php
new file mode 100644 (file)
index 0000000..c955c36
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ *  dolphin. Collection of useful PHP skeletons.
+ *  Copyright (C) 2019  Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * check if a string ends with a given string
+ *
+ * @param string $haystack
+ * @param string $needle
+ * @return boolean
+ */
+static function endsWith($haystack, $needle) {
+       $length = strlen($needle);
+       if ($length == 0) {
+               return true;
+       }
+       return (substr($haystack, -$length) === $needle);
+}
+
+?>
diff --git a/single-functions/starts-with.php b/single-functions/starts-with.php
new file mode 100644 (file)
index 0000000..0584dc1
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+/**
+ *  dolphin. Collection of useful PHP skeletons.
+ *  Copyright (C) 2019  Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program.  If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * check if a string starts with a given string
+ *
+ * @param string $haystack
+ * @param string $needle
+ * @return boolean
+ */
+function startsWith($haystack, $needle) {
+       $length = strlen($needle);
+       return (substr($haystack, 0, $length) === $needle);
+}
+
+?>