mardi 15 décembre 2020

php find string in text box

I need help with my php website. I need to search if textbox include some text. Its working only on half. When i type "Kdy" it works but when i type "Kdy prijdes" it wont works. I need to change output when textbox include some part of textbox but my idea wont work. Any solutions? Btw how are you guys?

    <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)];
    }
}
?>



Aucun commentaire:

Enregistrer un commentaire