From 4eeaa999f4be178c3a756194395979285eb73ca8 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 22:47:51 +0000 Subject: [PATCH 01/12] Did I find the needle in the haystack? --- src/string_search.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/string_search.php diff --git a/src/string_search.php b/src/string_search.php new file mode 100644 index 0000000..2772f38 --- /dev/null +++ b/src/string_search.php @@ -0,0 +1,14 @@ + \ No newline at end of file From 3f115e2b2457228c62e61ba37fb5497c7a60ca0b Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 22:51:20 +0000 Subject: [PATCH 02/12] Missing curly bracket, as usual. --- src/string_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index 2772f38..d88f72c 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -7,7 +7,7 @@ function string_search($needle, $haystack) { return false; echo "'$needle' was not found in '$haystack.'"; } else { - echo "'$needle' was found in '$haystack' at '$pos'." + echo "'$needle' was found in '$haystack' at '$pos'."; } } From 1b4fea5e03996530d1b1cb347227c381db77c949 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 23:18:21 +0000 Subject: [PATCH 03/12] Trying again? --- src/string_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index d88f72c..fb2e6ef 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -6,7 +6,7 @@ function string_search($needle, $haystack) { if ($needle === "") { return false; echo "'$needle' was not found in '$haystack.'"; - } else { + } elseif ($needle === "" || $needle === 0) { echo "'$needle' was found in '$haystack' at '$pos'."; } } From 2f413e324cc664aa5d0c7fbcb2b92b0aab6c1f6e Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 23:21:22 +0000 Subject: [PATCH 04/12] Trying again. --- src/string_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index fb2e6ef..3bbb857 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -6,9 +6,9 @@ function string_search($needle, $haystack) { if ($needle === "") { return false; echo "'$needle' was not found in '$haystack.'"; - } elseif ($needle === "" || $needle === 0) { + } else { echo "'$needle' was found in '$haystack' at '$pos'."; } } -/?> \ No newline at end of file +?> \ No newline at end of file From 4b34a84c43d6017c23b9b72b157389c4802adc51 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 23:25:29 +0000 Subject: [PATCH 05/12] Variable in the function. --- src/string_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 3bbb857..67d7ff4 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,8 +1,8 @@ Date: Tue, 21 Jun 2016 23:33:53 +0000 Subject: [PATCH 06/12] Ugh. --- src/string_search.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 67d7ff4..65bb296 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -5,9 +5,8 @@ function string_search($needle, $haystack) { if ($needle === "") { return false; - echo "'$needle' was not found in '$haystack.'"; } else { - echo "'$needle' was found in '$haystack' at '$pos'."; + return "Found '" . $needle . "' at index " . $pos; } } From 90fbcb07896f1be340b1ba9fc52aea6a461f8a2a Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 21 Jun 2016 23:37:23 +0000 Subject: [PATCH 07/12] Buuuuuuuh. --- src/string_search.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 65bb296..bd12fe0 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,8 +1,8 @@ Date: Tue, 21 Jun 2016 23:41:39 +0000 Subject: [PATCH 08/12] Failure. --- src/string_search.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index bd12fe0..429f2da 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,11 +1,12 @@ Date: Tue, 28 Jun 2016 22:24:32 +0000 Subject: [PATCH 09/12] This is the worst day of my life. --- src/string_search.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/string_search.php b/src/string_search.php index 429f2da..a3b9b69 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -8,6 +8,8 @@ function string_search($needle, $haystack) { return false; } elseif ($pos || $pos === 0) { return "Found '" . $needle . "' at index " . $pos; + } else { + return false; } } From f196cff7ad7a4328b0c4dbdbcc3ade3fc27cd550 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 28 Jun 2016 22:38:30 +0000 Subject: [PATCH 10/12] This is terrible. --- src/string_search.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index a3b9b69..429f2da 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -8,8 +8,6 @@ function string_search($needle, $haystack) { return false; } elseif ($pos || $pos === 0) { return "Found '" . $needle . "' at index " . $pos; - } else { - return false; } } From 6bf7416ba9cdb80c057121865cd01e6b615a3d63 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 28 Jun 2016 22:44:44 +0000 Subject: [PATCH 11/12] Trying again. --- src/string_search.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 429f2da..7699558 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -2,12 +2,14 @@ function string_search($needle, $haystack) { - $pos = strpos($needle, $haystack); - - if ($needle === "") { + if ($needle === "") { return false; - } elseif ($pos || $pos === 0) { + } + $pos = strpos($haystack, $needle); + if ($pos >= 0) { return "Found '" . $needle . "' at index " . $pos; + } else { + return false; } } From ac01cef9641eb26f6eff87e49089db07ca2373d1 Mon Sep 17 00:00:00 2001 From: Nicholas Dixon Date: Tue, 28 Jun 2016 22:53:29 +0000 Subject: [PATCH 12/12] Trying one more time. --- src/string_search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index 7699558..bea4621 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -6,7 +6,7 @@ function string_search($needle, $haystack) { return false; } $pos = strpos($haystack, $needle); - if ($pos >= 0) { + if ($pos !== false) { return "Found '" . $needle . "' at index " . $pos; } else { return false;