$words = array('SEO专家','搜索引擎', '关键词', '收录', '逗号分隔'); 用php判断$text中是否包含以上关键字,如果包含,重新获取$text内容并重新判断
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
<?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.
AI智能问答网
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用创作工场,更聪明、更完整、更原创!