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.