我一般是PHP和编程方面的新手。我正在寻找在文本正文中搜索句子或单词的示例或功能。
谢谢
马特
答案 0 :(得分:0)
这是一个如何在另一个文本字符串中查找文本字符串位置的示例。
$text = "The quick brown fox jumped over the lazy dog.";
$word = "quick";
$text_position = strpos($text, $word);
# $text_position is 4
答案 1 :(得分:0)
您可以在下面使用此示例。
<?php
$textYouAreSearchingFor = "vestibulum";
$fullBody = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eget tempus lorem. Donec sagittis massa dui, sed consequat eros suscipit quis. Curabitur accumsan tortor eu vulputate volutpat. Ut accumsan odio justo, vitae semper nunc tristique sed. Pellentesque sit amet leo bibendum, finibus metus a, elementum tortor. Etiam finibus efficitur ligula ac vulputate. Proin vitae tristique arcu. Curabitur vestibulum libero ante, gravida blandit tortor gravida in. Curabitur tincidunt rhoncus nisi in mattis. Phasellus fermentum magna eu nibh aliquet, non sagittis erat tem ....';
if(stristr($fullBody, $textYouAreSearchingFor) !== FALSE) {
echo "Hey, we found '{$textYouAreSearchingFor}' in full body text";
}
?>