S
S
santavits2020-05-04 23:54:34
PHP
santavits, 2020-05-04 23:54:34

How can I find out if a variable contains one of the listed characters?

Hello.

There was such task
there is a variable, let's say

$a = ''Hello moto;

And you need to find out if there are characters h and t in this variable.

How can this be implemented? what function would you recommend to use for this?
And how to list all characters to be searched?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Igor, 2020-05-05
@santavits

$re = '/[eps]/m';
$str = 'help me please';

preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

// Print the entire match result
var_dump($matches);

E
edward_freedom, 2020-05-05
@edward_freedom

It should have been written in the book you are reading
https://www.php.net/manual/en/function.strrpos.php

M
Mikhail Ushenin, 2020-05-05
@usheninmike

If the task is this:

How can I find out if a variable contains one of the listed characters?

then use the strpbrk function .
And if it's like this:
$a = ''Hello moto;
And you need to find out if there are characters h and t in this variable.

then use the preg_match function .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question