Hello!
I don’t know if this can be done: It is necessary that the condition only checks the initial word. For example, $var = 'magazine%'; Instead of % , anything can go, for example, in the search operator like % is put at the beginning and at the end, which means anything can go before the request and after the request. So I need if the value of a variable begins with a certain word, then perform an action.
It is necessary to highlight the section on the server side (add a class).
|
2 answers
Everything is solved easier nowhere. PHP has a special function for this: strpos
strpos - Returns the position of the first occurrence of a substring
Your example:
$var = 'magazine%'; // Если в начале исходной строки встретилось 'magazine' if (strpos($var, 'magazine') === 0) { // Добавить класс } - Gorgeous! Thanks to both! And I puzzle the second day, how to shine patterns ... - torawhite
|
Elementary Watson:
<? $var = 'magazine shop'; if(preg_match('!^magazine.*!', $var)){ // Выполняем подсветку или что там. } |