• 智能AI问答!更聪明、更完整、原创作!
  • 一款基于GPT的超级AI机器人,可以回答问题、聊天、创作、写文案!

$words = array('SEO专家','搜索引擎', '关键词', '收录', '逗号分隔'); 用php判断$text中是否包含以上关键字,如果包含,重新获取$text内容并重新判断

发布于 2023-11-08 03:13:47

Sure! Here's the PHP code to check if the variable $text contains any of the keywords in the array $words. If it does, it will reassign a new value to $text and then recheck for the keywords again.

<?php
$words = array('SEO专家', '搜索引擎', '关键词', '收录', '逗号分隔');
$text = "这是一个包含关键词的示例文本";

foreach ($words as $word) {
    if (strpos($text, $word) !== false) {
        // If the keyword is found, reassign a new value to $text and recheck
        $text = "新的文本内容"; // Replace with your new text content
        echo "Found keyword: " . $word . "\n";
        // ...
    }
}
?>

In this example, the array $words contains the keywords you want to check for. The variable $text initially contains the sample text "这是一个包含关键词的示例文本". The code uses a foreach loop to iterate through each keyword in the array and checks if it is present in the text using the strpos() function. If a keyword is found, you can replace the echo statement with your desired code to be executed. After finding a keyword, it reassigns a new value to $text and continues to check for the remaining keywords.

0 条评论

发布
问题

在线
客服