用PHP写一段代码代码作用是通过GPT生成一篇500字文章判断生成的内容中是否有exceeded your current quota和key is associated with a deactivated account如果有就用当前目录中atxt文件的第一行内容替换掉ai_article_gptphp文件的第14行内容替换后删除atxt的第一行内容
以下是通过PHP编写的满足您需求的代码:
<?php
// 读取 a.txt 文件的第一行内容
$replacement = file("a.txt")[0];
// 读取 ai_article_gpt.php 文件的内容
$code = file_get_contents("ai_article_gpt.php");
// 判断生成的内容中是否包含指定字符串
$found1 = strpos($code, 'exceeded your current quota') !== false;
$found2 = strpos($code, 'key is associated with a deactivated account') !== false;
// 如果包含指定字符串,则进行替换和删除操作
if ($found1 || $found2) {
// 替换 ai_article_gpt.php 文件的第14行内容
$lines = explode("\n", $code);
$lines[13] = $replacement;
$code = implode("\n", $lines);
// 将修改后的代码写回 ai_article_gpt.php 文件
file_put_contents("ai_article_gpt.php", $code);
// 删除 a.txt 文件的第一行内容
$file = file("a.txt");
unset($file[0]);
file_put_contents("a.txt", implode("", $file));
}
?>
注意:请将上述代码保存为一个独立的PHP文件,并确保在同一目录下存在 ai_article_gpt.php 和 a.txt 文件
原文地址: http://www.cveoy.top/t/topic/hU4B 著作权归作者所有。请勿转载和采集!