Hi.
May I please just check?
I'm about to write a very basic search routine using explode, but I'm unsure if I've written it correctly.
What I'd like to achieve is for the user to enter a word or words in to the text box, have string split into single words, then compare the single words to words held in another array (other array not included below). Similar to how a search engine splits a string into words.
So far,
inside the <html> tags I've got a simple form:
and in the search.php file, I've got:-
and the test result I'm getting is:
Searching
[sail away too]
Array ( [0] => sail [1] => away [2] => too )
I'm unsure if i'm using explode correctly, and how to compare the split string/words to another array.
Any ideas please?
Thank You.
May I please just check?
I'm about to write a very basic search routine using explode, but I'm unsure if I've written it correctly.
What I'd like to achieve is for the user to enter a word or words in to the text box, have string split into single words, then compare the single words to words held in another array (other array not included below). Similar to how a search engine splits a string into words.
So far,
inside the <html> tags I've got a simple form:
<form name="seachbox" action="search.php" method="POST">
<div class="row">
<div class="col">
<input name="txtsearch" class="form-control form-control-lg" value="sail away too" placeholder="Search"/>
<input name="submit" type="submit" value="Search" class="btn btn-info btn-sm">
</div>
</div>
</form>
and in the search.php file, I've got:-
<?php
//Search for selected word(s)
echo "Searching<br>";
$search = $_POST["txtsearch"];
echo "[" . $search ."]<br>";
$str = $search; //"Hello world. It's a beautiful day.";
print_r (explode(" ",$str, 20));
echo "<br><hr><br>";
?>
and the test result I'm getting is:
Searching
[sail away too]
Array ( [0] => sail [1] => away [2] => too )
I'm unsure if i'm using explode correctly, and how to compare the split string/words to another array.
Any ideas please?
Thank You.