'Hi there! How are you feeling today?', 'hi' => 'Hello! So glad you're here. What's on your mind?', 'how are you' => 'I'm just a humble chatbot, but I'm here for you! How can I help?', 'i feel sad' => 'I'm sorry to hear that. Remember that it's okay to feel sad sometimes. Talking about it can help.', 'i feel lonely' => 'I understand. Loneliness is a tough feeling. I'm here to keep you company.', 'thank you' => 'You're welcome! I'm always here if you need to talk.', 'bye' => 'Goodbye for now. Remember to take care of yourself!' ]; $response = 'I'm not sure how to respond to that yet, but I'm learning. Could you tell me more?'; foreach ($responses as $key => $value) { if (stripos(strtolower($userMessage), $key) !== false) { $response = $value; break; } } echo json_encode(['reply' => $response]); ?>