From 3aa6f38bce9354023ceab09a2efb188fa792199e Mon Sep 17 00:00:00 2001 From: jnels Date: Tue, 20 Sep 2016 18:22:33 -0400 Subject: [PATCH 1/8] First crack at challenge. --- src/string_search.php | 11 +++++++++++ 1 file changed, 11 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..af441aa --- /dev/null +++ b/src/string_search.php @@ -0,0 +1,11 @@ + Date: Tue, 20 Sep 2016 18:38:33 -0400 Subject: [PATCH 2/8] 2nd try after reading directions --- src/string_search.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index af441aa..d7d6b86 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -2,10 +2,10 @@ function string_search($haystack, $needle) { $search = strpos($haystack, $needle); - - if ($search) { + + if (is_int($search)) { return "Found '$needle' at index $search"; } else { - return "false"; + return false; } } \ No newline at end of file From aed4c9aa9dc9fa0c597de4d7855b07db1e60ade3 Mon Sep 17 00:00:00 2001 From: jnels Date: Tue, 20 Sep 2016 18:43:42 -0400 Subject: [PATCH 3/8] Dyslexia maybe? --- 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 d7d6b86..3a4a3ef 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,6 +1,6 @@ Date: Tue, 20 Sep 2016 18:50:31 -0400 Subject: [PATCH 4/8] Final answer. Maybe. --- src/string_search.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/string_search.php b/src/string_search.php index 3a4a3ef..e8234d9 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,6 +1,10 @@ Date: Tue, 20 Sep 2016 19:08:22 -0400 Subject: [PATCH 5/8] For real this time. With conviction. --- src/string_search.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index e8234d9..74771a4 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,15 +1,15 @@ = 0) { return "Found '$needle' at index $search"; } else { return false; } -} +} \ No newline at end of file From 3de206804afb3b9263a8949255078354e847a53d Mon Sep 17 00:00:00 2001 From: jnels Date: Tue, 20 Sep 2016 19:14:44 -0400 Subject: [PATCH 6/8] Clogging up the test --- src/string_search.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 74771a4..464ed9a 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -7,9 +7,11 @@ function string_search($needle, $haystack) { return false; } - if ($search >= 0) { + if (is_int($search)) { return "Found '$needle' at index $search"; } else { return false; } -} \ No newline at end of file +} + +var_dump(string_search('not there', 'Some string.')); \ No newline at end of file From f38afd0b201fe7185b0de5f13493d362b704a54f Mon Sep 17 00:00:00 2001 From: jnels Date: Tue, 20 Sep 2016 19:35:25 -0400 Subject: [PATCH 7/8] Yep --- src/string_search.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index 464ed9a..c8505dd 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -1,10 +1,10 @@ Date: Tue, 27 Sep 2016 19:09:38 -0400 Subject: [PATCH 8/8] Testing 1, 2, 3 --- src/string_search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/string_search.php b/src/string_search.php index c8505dd..bee9be6 100644 --- a/src/string_search.php +++ b/src/string_search.php @@ -3,10 +3,10 @@ function string_search($needle, $haystack) { if ($needle === "") { return false; - } else { - $search = strpos($haystack, $needle); - } - + } + + $search = strpos($haystack, $needle); + if (is_int($search)) { return "Found '$needle' at index $search"; } else {