Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/string_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
Accept two parameters, string to search for (needle)
and string to search (haystack). If needle is found
in haystack multiple times, return the first index.
Otherwise, return false. If needle is empty, return
false.
*/

function string_search($n, $h) {

if ($n == '') {
return false;
}

$pos = strpos ( $h, $n );

if ($pos === false) {
return false;
} else {
return "Found '" . $n . "' at index " . $pos;
}
}
?>