Answer the question
In order to leave comments, you need to log in
How to make a comparison and find a word in a string?
Friends, PHP gurus. There is such a list
CLIENTS==clients||
SERVICES==service||
CONTACTS==contacts
From it I get only the second part of the line, for example service
//что имеем на входе
<?php
$snippet = "service"; // часть строки из полного списка
$inputoptions = "КЛИЕНТЫ==clients||УСЛУГИ==service||КОНТАКТЫ==contacts"; //полный список
$snippets = explode('||',$inputoptions);
foreach ($snippets as $snippetoption){
$snippetoption_parts = explode('==',$snippetoption);
$value = isset($snippetoption_parts[0]) ? $snippetoption_parts[0] : '';
$text = isset($snippetoption_parts[1]) ? $snippetoption_parts[1] : $value;
if ($snippet == $value){
return $text;
}
}
return '';
Answer the question
In order to leave comments, you need to log in
you are looking in the wrong index
if ($snippet == $text) {
return $value;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question