<?php
session_start
();
include_once 
"shrinkconstants.php";
include_once 
"libshrink.php";
    
// Output as XML
    
echo '<data>';
    echo 
'<response>';
    
    if(!isset(
$_SESSION['punt_count'])) $_SESSION['punt_count'] = 0;
    if(!isset(
$_SESSION['word_count'])) $_SESSION['word_count'] = 0;
    
// Sanitize user input and convert string to lower case
    
$user_input strtolower(filter_var($_POST['input'], FILTER_SANITIZE_STRING));
    
$input you_me_map($user_input);
    
$word "";
    
    if(
preg_match(BYE_REGEX$input)) {
        echo 
"Goodbye.";
    } else if(
preg_match(YOU_ARE_REGEX$input$matches)) {
        echo 
"Please tell me " wword(++$_SESSION['word_count']) . " you are " $matches['input'] . ".";
    } else if(
preg_match(YOU_HAVE_REGEX$input$matches)) {
        echo 
"How long have you had " $matches['input'] . "?";
    } else if(
preg_match(YOU_FEEL_REGEX$input)) {
        echo 
"I sometimes feel the same way.";
    } else if(
preg_match(BECAUSE_REGEX$input)) {
        echo 
"Is that really the reason?";
    } else if(
$input == "") {
        echo 
"Please say something!";
    } else if(
preg_match(YES_REGEX$input$matches)) {
        echo 
"How can you be so sure " $matches['input'] . "?";
    } else if(
preg_match(ME_ARE_REGEX$input$matches)) {
        echo 
"Oh yeah I am " $matches['input'] . ".";
    } else if(
preg_match(THINK_REGEX$input)) {
        echo 
"I think you should answer that yourself.";
    } else if(
$word verbp($input)) {
        echo 
"Why do you want to " $word "?";
    } else if(
$word wpred($input)) {
        echo 
"You tell me " $word;
    } else if(
$word dpred($input)) {
        echo 
"Perhaps I " $word "."
    } else if(
preg_match(DREAM_REGEX$input)) {
        echo 
"For dream analysis, see Freud.";
    } else if(
preg_match(LOVE_REGEX$input)) {
        echo 
"All is fair in love and war.";
    } else if(
in_array(NOexplode(" "$input)))     {
        echo 
"Don't be so negative.";
    } else if(
preg_match(MAYBE_REGEX$input)) {
        echo 
"Be more decisive!";
    } else if(
preg_match(YOU_REGEX$input)) {
        echo 
$input;
    } else {
        echo 
punt(++$_SESSION['punt_count']);
    }
    
    echo 
'</response>';
    echo 
'</data>';
?>