在PHP中搜索多个字符串的文本可以使用多种方法,以下是几种常见的方法:
$text = "This is a sample text";
$keywords = array("sample", "text");
foreach ($keywords as $keyword) {
if (strpos($text, $keyword) !== false) {
echo "Found: " . $keyword . "<br>";
} else {
echo "Not found: " . $keyword . "<br>";
}
}
$text = "This is a sample text";
$keywords = array("sample", "text");
foreach ($keywords as $keyword) {
if (preg_match("/" . $keyword . "/", $text)) {
echo "Found: " . $keyword . "<br>";
} else {
echo "Not found: " . $keyword . "<br>";
}
}
$text = "This is a sample text";
$keywords = array("sample", "text");
foreach ($keywords as $keyword) {
if (stristr($text, $keyword)) {
echo "Found: " . $keyword . "<br>";
} else {
echo "Not found: " . $keyword . "<br>";
}
}
以上是在PHP中搜索多个字符串的文本的几种常见方法。根据具体需求和场景选择合适的方法进行使用。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云