age here if it is greater or less than the age typed by the user
The question is how do I get the age of a message written by the user.
If you only need the number of age, get only digit from $text and compare it
$user_age = 20; if (preg_match("/Age:\s*(\d+)/", $text, $matches)) { $message_age = $matches[1]; if ($message_age > $user_age) { // do something if message age is greater than user age } else { // do something if message age is less than or equal to user age } } else { // do something if age is not found in message }
Обсуждают сегодня