It is necessary to set my title on certain pages, for this I use the following construction

$url = $_SERVER["REQUEST_URI"]; switch($url){ case preg_match("/contacts/i", $url): echo '<title>Контакты</title>'; break; case preg_match("/services/i", $url): echo "<title>service</title>"; break; default: echo "<title>Главная</title>"; echo "<link rel='stylesheet' href='css/flexslider.css'>"; } 

Tell me why she does not work right?

  • preg_match returns 0/1, respectively switch condition change - Jean-Claude
  • It is necessary to replace switch with if/elseif/else . From him there is no sense to vseravno. - Arnial
  • In this version, I need to use only a switch. That the condition to change is understandable is simply a question in what to replace it with? - ChromeChrome

1 answer 1

Replace with true :

 switch(true){ case preg_match("/contacts/i", $url): echo '<title>Контакты</title>'; break; case preg_match("/services/i", $url): echo "<title>service</title>"; break; default: echo "<title>Главная</title>"; echo "<link rel='stylesheet' href='css/flexslider.css'>"; }