I
I
Ilya Korablev2015-12-05 18:24:54
PHP
Ilya Korablev, 2015-12-05 18:24:54

How to create a regular expression?

Help create a regular expression.
Necessarily, if the $text variable had the value "weather", "time" or "news" (for example), then the $text variable was displayed.
How to implement?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sunrails, 2015-12-05
@swipeshot

$text = 'погода';
$pattern = '#^(погода|время|новости)$#';

if (preg_match($pattern, $text, $match)) {
    echo $text;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question