2016-11-04 3 views
0

여기서는 다른 모든 입력에 사용할 수있는 코드를 사용하지만 hospital이 아닌 이유는 무엇입니까?왜 일부 경우 preg_match()가 일치하지 않는가

다른 필터를 제안하면이 필터를 사용해 주시면 대단히 감사하겠습니다.

데모를 참조하십시오 :이 it이 있기 때문에

$type = strtolower("hospital"); 

if(preg_match('/it|IT|it services|it service|it infrastructure|it infrastructures/',$type)){ 
    $img = "images/it1-200x111.jpg"; 
}else if(preg_match('/business|business solutions|biz solutions|business solution|biz solution/',$type)){ 
    $img = "images/business-200x111.jpg"; 
}else if(preg_match('/manpower|manpower solution|manpower solutions|manpower services|manpower service|human resource|human resources/',$type)){ 
    $img = "images/mp-1-200x111.jpg"; 
}else if(preg_match('/financial|finance|financial solution|financial solutions|financial service|financial services/',$type)){ 
    $img = "images/fin-200x111.jpg"; 
}else if(preg_match('/marketing|marketing solution|marketing solutions|marketing service|marketing services/',$type)){ 
    $img = "images/mark1-200x111.jpg"; 
}else if(preg_match('/real estate|real estates|real estate solution|real estates solution|real estate solutions/',$type)){ 
    $img = "images/real1-200x111.jpg"; 
}else if(preg_match('/school|schooling services|school services|schools service|schooling service/',$type)){ 
    $img = "images/school1-200x111.jpg"; 
}else if(preg_match('/college|college service|college services|colleges/',$type)){ 
    $img ="images/coll1-200x111.jpg"; 
}else if(preg_match('/hospital|hospitals|hospital service|hospital services/',$type)){ 
    $img = "images/hosp-1-200x111.jpg"; 
}else{ 
    $img = "images/it1-200x111.jpg"; 
} 

echo $img; 
+0

병원이 URL에있을 때를 의미합니다. 작동하지 않습니다. ..? –

+1

병원에'it'이 있기 때문에 – jamesjaya

+0

$ 유형은 입력 할 조건을 결정하지만 병원 섹션에 입력하지 않습니다. 다른 사람이 입력하는 경우 – EaBangalore

답변

3

hospital 첫 번째 조건과 일치 : http://phpio.net/s/cgv

가 여기 내 코드입니다. 시작/시작 기호 ^을 조건에 추가하십시오. 예를 들어 ^it 인 경우 문자열이 it으로 시작하는 경우에만 일치합니다.

+0

phpio.net에서 데모를 할 수 있습니다 – EaBangalore

+0

http://phpio.net/s/ci0 – jamesjaya

관련 문제