I need help with my PHP website. I need to search if textbox includes some text. Its working only on half. When I type "Kdy" it works but when I type "Kdy prijdes" it wont work. I need to change output when textbox includes some part of textbox but my idea wont work. Any solutions?
<h1>Zeptej se mě</h1>
<form id="frm" method="POST" action="?action">
<input type = "text" name = "textbox" value = ""/>
<input type="submit" value="Odešli" id="submit"/>
</form>
<?php
if(isset($_GET['action']))
{
$text = $_POST['textbox'];
$kde = array("kde", "Kde");
$kam = array("kam", "Kam");
$kdy = array("kdy", "Kdy");
$jak = array("jak", "Jak");
$co = array("co", "Co");
$proc = array("proč", "proc", "Proč", "Proc");
$kdo = array("kdo", "Kdo");
$koho = array("koho", "Koho");
if (in_array($text, $kde))
{
echo "Nikde";
}
elseif(in_array($text, $kam))
{
echo "Nikam";
}
elseif(in_array($text, $kdy))
{
echo "Nikdy";
}
elseif(in_array($text, $jak))
{
echo "Nevim";
}
elseif(in_array($text, $co))
{
echo "Nic";
}
elseif(in_array($text, $proc))
{
echo "Nevim";
}
elseif(in_array($text, $kdo))
{
echo "Nikdo";
}
elseif(in_array($text, $koho))
{
echo "Nikoho";
}
else
{
$text = array("Spíš ne", "Asi", "No nevím");
echo $text[array_rand($text)];
}
}
?>
in_arrayis the wrong function for what you're trying to do.strposis the way to go.explode()to split the text field into separate words and search for each of them.