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

写一段php代码,判断$text中是否包含 11 22 33 44 55 66 ,如果包含 执行其他代码,如果不包含跳出循环

发布于 2023-11-08 03:05:43

Sure! Here's the PHP code to check if the variable $text contains any of the values 11, 22, 33, 44, 55, or 66. If it does, it will execute other code. If it doesn't, it will break out of the loop.

<?php
$text = "This is a sample text containing 11 and 77";

$keywords = array(11, 22, 33, 44, 55, 66);

foreach ($keywords as $keyword) {
    if (strpos($text, strval($keyword)) !== false) {
        // Execute other code here if $text contains the keyword
        echo "Found keyword: " . $keyword . "\n";
        // ...
    } else {
        // Break out of the loop if $text does not contain the keyword
        break;
    }
}
?>

In this example, the variable $text contains the sample text "This is a sample text containing 11 and 77". The code checks if any of the keywords 11, 22, 33, 44, 55, or 66 are 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. If none of the keywords are found, the loop will break and exit.

0 条评论

发布
问题

在线
客服