### 首先说明,这是在网上看到的,代码中附带出处,谢谢。 >> 估值1个忆的 AI 核心代码部分,不得商用:sunglasses: ```php /** * AI 核心代码,估值1个亿 * User: wangyongdong * DateTime: 2019/10/30 16:05 * Refer: https://github.com/ruanyf/weekly/issues/158 */ class AIMain { public static $question; public static function eol() { $os = strtoupper(PHP_OS); if (php_sapi_name() != 'cli') { return ''; } if(strpos("WIN", $os) !== FALSE) { return "\r\n"; } if(strpos("LINUX", $os) !== FALSE) { return "\n"; } if(strpos("MAC", $os) !== FALSE) { return "\r"; } } public static function ask(string $string) { self::$question = $string; return sprintf('我:%s%s', self::$question, self::eol()); } public static function answer() { $answer = str_replace(['吗', '?', '?'], ['', '!', '!'], self::$question); return sprintf('机器人:%s%s', $answer, self::eol()); } } $AIMain = new AIMain(); echo $AIMain->ask('在吗?'); echo $AIMain->answer(); ```