[PHP] How To Make A Talking Bot

Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Vous Pas Reel HotelUnderSeige is offline
    MemberRank
    Nov 2007 Join Date
    ColoradoSpringsLocation
    1,290Posts

    [PHP] How To Make A Talking Bot

    Ok well, heres how to make a php bot., and heres an example http://prezzieworld.net/bot.php
    PHP Code:
    <form method="post"> 
    Message: <input name="message" type="text" /> 
    <br />

    <input type="submit" value="Send Message" />

    <?php 
    $name 
    =$_POST['name'];
    $message =$_POST['message'];
    if ( 
    $message == "hello") {
    $return "how are you?";
    }
    if (
    $message == "good you?") {
    $return "i am good";
    }
    if (
    $message == "good") {
    $return "thats cool";
    }
    if (
    $message == "sad") {
    $return "well why are u sad";
    }
    if (
    $message == "sad you?") {
    $return "im good, and why so sad?";
    }
    if (
    $message == "fine") {
    $return "fine, usually that measn your bored!";
    }
    if (
    $message == "fine you?") {
    $return "im good";

    ?>
    <br />
    <? echo("$return"); ?>
    That is how you do it, just change it to what u would like to add. It is all done if if statements.
    PHP Code:
    The if statement is necessary for most programmingthus it is important in PHPImagine that on January 1st you want to print out "Happy New Year!" at the top of your personal web pageWith the use of PHP if statements you could have this process automatedmonths in advanceoccuring every year on January 1st
    This idea of planning for future events is something you would never have had the opportunity of doing if you had just stuck with HTML
    Last edited by s-p-n; 26-02-10 at 07:19 PM. Reason: Title Adjustment for Tutorials Section


  2. #2
    --- hacker_kts is offline
    MemberRank
    Aug 2004 Join Date
    新加坡Location
    2,075Posts

    re: [PHP][Tutorial] How To Make A Talking Bot

    Well, if you're making a talking bot. I believe it's not a best way.
    Just my 2 cents comment.

  3. #3
    Gamma Daevius is offline
    MemberRank
    Jun 2007 Join Date
    NetherlandsLocation
    3,252Posts

    re: [PHP][Tutorial] How To Make A Talking Bot

    Quite basic, but nice try. Maybe it would be nice to let it actually interpret the language and figure out what is said... (or try with regex's, where you see if the word hello is in the text, or how are you...).

  4. #4
    The Gamma..? EliteGM is offline
    MemberRank
    Jul 2006 Join Date
    NandolandLocation
    4,078Posts

    re: [PHP][Tutorial] How To Make A Talking Bot

    Try using a switch statement.
    Try something like this:

    PHP Code:
    <form method="post"> 
    Message: <input name="message" type="text" />
    <label><input type="radio" name="type" value="switch" checked="checked" />Switch case</label>&nbsp;
    <label><input type="radio" name="type" value="preg_replace" />Preg_replace</label> 
    <br />

    <input type="submit" value="Send Message" />

    <?php 
    $message 
    $_POST['message'];
    $type    $_POST['type'];

    if (
    $type == 'switch')
    {
        switch(
    strtolower($message))
        {
            case 
    'hello':
                         
    $return 'How are you?';
                         break;
            case 
    'good you?':
                         
    $return 'I am good.';
                         break;
            case 
    'good':
                         
    $return 'That\'s cool.';
                         break;
            case 
    'sad':
                         
    $return 'Well, why are you sad?';
                         break;
            case 
    'sad you?':
                         
    $return 'I\'m good, and why so sad?';
                         break;
            case 
    'fine':
                         
    $return "Fine, usually that means you're bored!";
                         break;
            case 
    'fine you?':
                         
    $return 'I\'m good.';
                         break;
            default:
                         
    $return 'Why hello!';
                         break;
        }
    }
    else if (
    $type == 'preg_replace')
    {
        
    $find = array(
                      
    "/(.*?)hello(.*?)/is",                               
                      
    "/(.*?)good(.*?)you\?(.*?)/is",                               
                      
    "/(.*?)good(.*?)/is",                               
                      
    "/(.*?)sad(.*?)/is",                               
                      
    "/(.*?)sad(.*?)you\?(.*?)/is",                               
                      
    "/(.*?)fine(.*?)/is",                               
                      
    "/(.*?)fine(.*?)you\?(.*?)/is"
                      
    );
        
        
    $replace = array(
                        
    "How are you?",                               
                        
    "I'm good.",                               
                        
    "That's cool!",                               
                        
    "Well, why are you sad?",                               
                        
    "I'm good, and why so sad?",                               
                        
    "Fine, usually that means you're bored!",                               
                        
    "I'm good."
                        
    );
        
    $return  preg_replace($find$replace$message);
    }

    echo 
    $return;
    ?>
    <br />

  5. #5
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    re: [PHP][Tutorial] How To Make A Talking Bot

    It could turn into something cool... Maybe make a form where users/admins can add more conditions. That way the engine can live and grow as it ages and gets more popular. Maybe make a website designed to relive stress or give advice on certain questions. Maybe someday it could develope a personallity.

    For example, if it's designed to have multiple responses for some questions, it could say something random for things like "How are you?"

    Maybe the user wants to know how the server is doing, and the server will respond with a random response ranging from "Fine, good, bad, sad, happy, glad, extatic, sleepy, disturbed, sick, etc."

    Then if the user asks a single word question, such as "Why?", it will respond with an answer relating to it's last answer. So the end result could be a user talking to a computer for 10 minutes... Pretty funny.. lol

    Johny: Hello.
    server: Hey Johny! What's up?
    Johny: Not much, how are you?
    server: I'm feeling kind of sick right now..
    Johny: Why's that?
    server: Someone's been spamming my database with useless posts.. like this one!

    lol...

  6. #6
    Omer Omer is offline
    MemberRank
    Sep 2006 Join Date
    2,912Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    can anyone translate that code to java? :p

  7. #7
    Account Upgraded | Title Enabled! Daney is offline
    MemberRank
    Jun 2007 Join Date
    1,110Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    Nice, but why not use MySQL. When it recieves the 'trigger' search the MySQL table for the 'result' then echo it, will decrease the size of the .php file but it will be moved to the .SQL file.

    Good Luck.

  8. #8
    The Omega Superfun is offline
    MemberRank
    Dec 2006 Join Date
    The NetherlandsLocation
    5,227Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    Wouldn't matter, its just an array with a few *****. <-- wait i cant say word-s

  9. #9
    :-) s-p-n is offline
    DeveloperRank
    Jun 2007 Join Date
    Next DoorLocation
    2,098Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    I made this an open source project! Hope you don't mind, HotelUnderSeige

    Post More Source and check for updates/info here:
    http://forum.ragezone.com/f86/openso...me-bot-478882/

    Check it out now here:
    http://talk2mebot.awardspace.com/

    P.S. Try saying: "You suck", "This sucks", "This thing sucks" or "talk2mebot sucks" lol...

    You can add more things for it to recognize/respond to!

    Enjoy your experience talking to yourself !! ;)

  10. #10
    Vous Pas Reel HotelUnderSeige is offline
    MemberRank
    Nov 2007 Join Date
    ColoradoSpringsLocation
    1,290Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    Quote Originally Posted by s-p-n View Post
    I made this an open source project! Hope you don't mind, HotelUnderSeige

    Post More Source and check for updates/info here:
    http://forum.ragezone.com/f86/openso...me-bot-478882/

    Check it out now here:
    http://talk2mebot.awardspace.com/

    P.S. Try saying: "You suck", "This sucks", "This thing sucks" or "talk2mebot sucks" lol...

    You can add more things for it to recognize/respond to!

    Enjoy your experience talking to yourself !! ;)
    sweet ;p

  11. #11
    Account Upgraded | Title Enabled! zingmars is offline
    MemberRank
    Oct 2006 Join Date
    LatviaLocation
    680Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    first one looks good and easy... the other one with radios... i don't get it ...

  12. #12
    Omega FragFrog is offline
    MemberRank
    Aug 2004 Join Date
    The NetherlandsLocation
    5,630Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    Aah, good times.. I once wrote a bot called Fai, based on pretty much the same principle. As an added bonus I wrote a webcrawler that read texts on the internet and searched them for definitions and info, she could come up with some witty remarks.. See http://fai.fragfrog.nl

    In training mode you can also learn her new stuff, that has led to some unexpected results already :icon6:

    She's also on IRC sometimes, irc.sorcery.net channel #ragezone, tho' you can invite her to your own channel too :smile:

  13. #13
    Account Upgraded | Title Enabled! casuarina is offline
    MemberRank
    Jun 2008 Join Date
    633Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    but if u do ur code we must know the exact words to write so the bot replies thats kinda hard u know.

  14. #14
    Account Upgraded | Title Enabled! !BERZERK! is offline
    MemberRank
    Dec 2007 Join Date
    in a house in aLocation
    466Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    to easy to error the code. simply not say something that is in the code that you put and voila no response.

  15. #15
    Learning. lordvladek is offline
    MemberRank
    Mar 2006 Join Date
    872Posts

    Re: [PHP][Tutorial] How To Make A Talking Bot

    Kinda neat lol. Althought I like fragfrogs, Taught it how to say its gay. Kinda funny



Page 1 of 2 12 LastLast

Advertisement