how can php determine the presence of a certain word in the text?
Closed due to the fact that off-topic participants Edward , Enikeyschik , Kirill Malyshev , Sergey Glazirin , Air 21 Nov '18 at 18:28 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- " Learning tasks are allowed as questions only on condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Enikeyschik, Kirill Malyshev, Sergey Glazirin, Air
- 9Minus for the complete lack of independent attempts to find a solution. - Enikeyschik
|
1 answer
If I understand you correctly, then you want to find a substring in the string. This can be done using the strpos method.
// строка в которой вы ищете слово $mystring = 'Текст с 4 словами'; //слово, которое вы ищете $findme = 'Текст'; $pos = strpos($mystring, $findme); if (false === $pos) { echo 'слово ' . $findme . ' не найдено'; } else { echo 'слово ' . $findme . ' найдено в позиции ' . $pos; } In addition, you can solve this problem using regular expressions. Or you can write your own method to search for substrings in the string.
But for simple things, I use exactly strpos.
|