Я не знаю, что MySQL есть несколько вариантов для этого. Но вы можете разбить строку и найти имена.
$sentence = "Mark and Paul are very good friends since 2000."
//some code to get all names from the database
//simulation mysql-output as array
$names = array("Mark", "Mike", "Paul", "John");
//first split the String into a array what contains all words of the sentences
$array = explode(" ", $sentence);
//now you can check if any words in the array eqauls a name in your database
//create a foreach loop to check all words
foreach($array as $word) {
//search if the word contains in the array
if(in_array($word, $names)) {
//this word is a searched name
print_r("Word ".$word." is a name!\n");
}
else {
//this word isn't a name
}
}
В случае If/Else вы можете закодировать обработчик custum. Обратите внимание, если предложение заканчивается точкой, которую последнее слово имеет в последнем знаке точку (.). Вы можете проверить его и удалить точку с помощью функции substr
.
Я не тестирую код.
Это не та вещь, что SQL является очень хорошо, так что, несмотря на кажущуюся над головой, я был бы соблазн найти решение в коде уровня приложения. – Strawberry