Answer the question
In order to leave comments, you need to log in
Is it possible to immediately assign a variable in one action, get [0] from it and compare?
Hello. I need to make a condition under which I check if the line starts with the word "Delete" and if so, I process the second part of the code.
$msg = 'Удалить Александр Петров';
if(mb_strtolower(explode(' ',trim($msg), 2)[0] == 'удалить') {
// здесь нужно работать c "Александр Петров"
}
Answer the question
In order to leave comments, you need to log in
$msg = 'Удалить Александр Петров';
$command = explode(' ', trim($msg), 2);
if(mb_strtolower($command[0]) === 'удалить') {
// здесь нужно работать c $command[1]
}
If I felt sorry for using regular expressions, I would use mb_strlen()
- to count the number of characters in the 'Delete' string (well, or not count, but write it myself). Then mb_stripos()
to check if the line contains the desired line (Delete) and whether it is at the beginning. Then, mb_substr()
in order to pull out the "second part of the code".
PS Online or go to the registry office?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question