From fe00ffac1dfb6247d47a308aac76bd38cf8b1402 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Mon, 19 Sep 2016 22:36:14 -0400 Subject: [PATCH 01/14] string search challenge --- src/string_search.php | 17 +++++++++++++++++ 1 file changed, 17 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..e887e32 --- /dev/null +++ b/src/string_search.php @@ -0,0 +1,17 @@ + From c94880d9272f6d33819ba3b6db66512a188717c0 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Mon, 19 Sep 2016 22:52:34 -0400 Subject: [PATCH 02/14] null fixed --- src/string_search.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index e887e32..82d158b 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -3,15 +3,14 @@ function string_search($haystack, $needle){ $position = strpos($haystack, $needle); - if ($position == 0){ - echo "Found '$needle' at position $position"; - } elseif (!$position){ + if (!$haystack || !$needle) { return false; - } else { - echo "Found '$needle' at position $position"; - } + } elseif ($position == 0){ + echo "Found '$needle' at index $position"; + } elseif (!$position){ + return false; + } else { + echo "Found '$needle' at index $position"; + } } - - - ?> From cb96a8bf33ef885b94bf122a0aeda99dce50b069 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Mon, 19 Sep 2016 23:08:45 -0400 Subject: [PATCH 03/14] string search --- src/string_search.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 82d158b..4b25ffd 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -6,11 +6,12 @@ function string_search($haystack, $needle){ if (!$haystack || !$needle) { return false; } elseif ($position == 0){ - echo "Found '$needle' at index $position"; + echo "'Found '$needle' at index $position'"; } elseif (!$position){ return false; } else { - echo "Found '$needle' at index $position"; + echo "'Found '$needle' at index $position'"; } } +string_search("Some string", "string"); ?> From a6201dd70eed927bb52e5cd14638a6ee39309af4 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 18:17:04 -0400 Subject: [PATCH 04/14] echo changed to return --- src/string_search.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 4b25ffd..281d4e7 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -5,13 +5,13 @@ function string_search($haystack, $needle){ if (!$haystack || !$needle) { return false; - } elseif ($position == 0){ - echo "'Found '$needle' at index $position'"; - } elseif (!$position){ + }elseif ($position == 0){ + return "Found '$needle' at index $position"; + }elseif (!$position){ return false; - } else { - echo "'Found '$needle' at index $position'"; + }else { + return "Found '$needle' at index $position"; } } -string_search("Some string", "string"); + ?> From 0f11b87b7539d425eb3d6396b14e72ef681474b9 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 18:24:39 -0400 Subject: [PATCH 05/14] function order altered --- src/string_search.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 281d4e7..26629e1 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,5 +1,5 @@ +?> From 30f975a9bb76e4947ebc75bb124ac79c7a6d617a Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 18:41:17 -0400 Subject: [PATCH 06/14] zero equality changed --- 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 26629e1..fb88dc2 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -5,7 +5,7 @@ function string_search($needle, $haystack){ if (!$haystack || !$needle) { return false; - }elseif ($position == 0){ + }elseif ($position === 0){ return "Found '$needle' at index $position"; }elseif (!$position){ return false; From bdd4b93ae68acf3fd8350c65629b0cece76b1841 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 18:53:41 -0400 Subject: [PATCH 07/14] empty function added --- src/string_search.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index fb88dc2..32b160a 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -3,7 +3,7 @@ function string_search($needle, $haystack){ $position = strpos($haystack, $needle); - if (!$haystack || !$needle) { + if (!$haystack || !$needle || empty($haystack) || empty($needle)) { return false; }elseif ($position === 0){ return "Found '$needle' at index $position"; @@ -13,4 +13,5 @@ function string_search($needle, $haystack){ return "Found '$needle' at index $position"; } } + ?> From 105798a59bb7918809c4a6a5e32c4216f63f9efc Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:04:21 -0400 Subject: [PATCH 08/14] removed empy fuction --- src/string_search.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 32b160a..92f3308 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -3,15 +3,13 @@ function string_search($needle, $haystack){ $position = strpos($haystack, $needle); - if (!$haystack || !$needle || empty($haystack) || empty($needle)) { + if ($needle == false) { return false; - }elseif ($position === 0){ + }elseif ($position >=0){ return "Found '$needle' at index $position"; - }elseif (!$position){ - return false; - }else { - return "Found '$needle' at index $position"; - } + } else { + return false; + } } ?> From 6d360a7bae6c0abe90d04ed0217e53e23eb44770 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:06:06 -0400 Subject: [PATCH 09/14] removed empty function --- src/string_search.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index 92f3308..d6b1284 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -11,5 +11,4 @@ function string_search($needle, $haystack){ return false; } } - ?> From f7b24cc83878ad69b3abd34428d2fc9847af2e26 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:15:57 -0400 Subject: [PATCH 10/14] intval --- src/string_search.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index d6b1284..4069bdb 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,7 +1,7 @@ From 310855f743cf0947cc0545af62d3c30622ff8985 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:39:16 -0400 Subject: [PATCH 11/14] moved empty needle test --- src/string_search.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 4069bdb..31c2d94 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,15 +1,13 @@ =0){ + } + else { + $position = strpos($haystack, $needle); return "Found '$needle' at index $position"; - } else { - return false; - } + } } ?> From 0dcf2934cea8eaac1344e64186b87a7b09907bb5 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:56:33 -0400 Subject: [PATCH 12/14] >= statement --- src/string_search.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 31c2d94..d63d919 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -3,11 +3,14 @@ function string_search($needle, $haystack){ if ($needle==false) { return false; - } - else { - $position = strpos($haystack, $needle); + } else { + + $position = strpos($haystack, $needle); + + if ($position===0 | $position >0){ return "Found '$needle' at index $position"; - } + } + } } ?> From 48b3edec5390d730e5694e88d00c7c95cf7ad607 Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 19:57:33 -0400 Subject: [PATCH 13/14] new fork --- 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 d63d919..83f0700 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -11,6 +11,5 @@ function string_search($needle, $haystack){ return "Found '$needle' at index $position"; } } -} - +} ?> From ee7eb6caac06caa93d98de1e73a1b6b2a6e2641e Mon Sep 17 00:00:00 2001 From: Kathryn Date: Tue, 20 Sep 2016 20:37:40 -0400 Subject: [PATCH 14/14] false statement --- src/string_search.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index 83f0700..f355f9c 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -9,7 +9,9 @@ function string_search($needle, $haystack){ if ($position===0 | $position >0){ return "Found '$needle' at index $position"; + } else { + return false; } } -} +} ?>