2017-10-08 5 views
0

나는 여러 개의 PHP 파일의 머리 부분에서 메타 데이터를 호출하기 위해 PHP echo를 사용하고 있습니다. 알 수없는 이유로preg_match와의 충돌

<?php 

if (preg_match("@[email protected]", $_SERVER['REQUEST_URI'])) { 
$meta=<<<EOF 
<title>FR Contact title</title> 
<meta name="description" content="FR Contact description"> 
<link rel="alternate" href="https://site.ch/contact" hreflang="fr-CH" /> 
<link rel="alternate" href="https://site.ch/de/contact" hreflang="de-CH" /> 
<link rel="alternate" href="https://site.ch/it/contact" hreflang="it-CH" /> 
EOF; 
} 
elseif (preg_match("@de/[email protected]", $_SERVER['REQUEST_URI'])) { 
$meta=<<<EOF 
<title>DE Contact title</title> 
<meta name="description" content="DE Contact description"> 
<link rel="alternate" href="https://site.ch/de/contact" hreflang="de-CH" /> 
<link rel="alternate" href="https://site.ch/contact" hreflang="fr-CH" /> 
<link rel="alternate" href="https://site.ch/it/contact" hreflang="it-CH" /> 
EOF; 
} 
//echo ">>>>>" . $_SERVER['REQUEST_URI'] . "<<<<"; 
?> 

, 나는 비슷한 URL의 와 전화 충돌이 있습니다

여기
<?php 
include "$_SERVER[DOCUMENT_ROOT]/meta.php"; 
?> 

는 고유의 메타 파일이 모습입니다 : 모든 파일이 코드를 사용하여 고유 한 메타 파일을 포함 preg_match, 나라와 관련된 다른 폴더 이름에도 불구하고 : / 버그를 신고하고 프랑스어 설명을 표시하십시오.

그러나 폴더 이름을 약간 수정하는 경우 : de/kontakt이 작동하고 독일어 설명이 표시됩니다.

이 버그를 피하는 방법을 알려주십시오.

+0

는 대답은 질문을 해결합니까? – chris85

답변

0

첫 번째 preg_match에있는 contact이 두 URL과 일치하는 경우 정규식은 전체 문자열에서 모든 항목을 찾습니다. 주문을 교환 할 수 있습니다 :

if (preg_match("@de/[email protected]", $_SERVER['REQUEST_URI'])) { 
... 
} else { 
serve french 
} 

독일 식 경기가 시작되면이 방법으로이 방법을 사용할 수 있습니다. 그렇지 않으면 기본 프랑스어 콘텐츠를 제공하기 만하면됩니다. 당신이 elseif을 넣고 같은 preg_match을 할 수없는 경우 (즉 당신이 원하는 기능의 가정. 또한 kontakt을위한 정규식에 선택적인 용어를 넣을 수 있습니다.

if (preg_match("@de/(?:contact|kontakt)@", $_SERVER['REQUEST_URI'])) {