내 URL에 4 개의 매개 변수가 있습니다. 주어진 url에서 url 매개 변수를 검색합니다. 모든 매개 변수를 사용하여 디렉토리 경로를 변경하고 다른 이미지를 얻습니다. 이 같은PHP에서 복수 URL 매개 변수를 검색하는 방법
내 샘플 URL의 모습 :
www.sample.com?cat=section1&language=de&prices=pl
코드가 작동되지만은 spagheti 코드입니다.
DRY가 적은 솔루션이 있습니까? 어떻게 여러 URL 매개 변수를 검색합니까?
if(isset($_GET["cat"])) {
switch ($cat) {
case 'section1':
if(isset($_GET["language"])) {
$language = htmlspecialchars($_GET["language"]);
if($language == "de") {
if(isset($_GET["prices"])) {
$prices = htmlspecialchars($_GET["prices"]);
if($prices == "pl"){
$files=glob('pages/section1/dp/low/*.jpg');
}
else {
$files=glob('pages/section1/dn/low/*.jpg');
}
}
else {
$files=glob('pages/section1/dn/low/*.jpg');
}
}
elseif ($language == "en") {
if(isset($_GET["prices"])) {
$prices = htmlspecialchars($_GET["prices"]);
if($prices == "pl"){
$files=glob('pages/section1/ep/low/*.jpg');
}
else {
$files=glob('pages/section1/en/low/*.jpg');
}
}
else {
$files=glob('pages/section1/en/low/*.jpg');
}
}
elseif ($language == "cz") {
if(isset($_GET["prices"])) {
$prices = htmlspecialchars($_GET["prices"]);
if($prices == "pl"){
$files=glob('pages/section1/cp/low/*.jpg');
}
else {
$files=glob('pages/section1/cn/low/*.jpg');
}
}
else {
$files=glob('pages/section1/cn/low/*.jpg');
}
}
else {
$files=glob('pages/section1/cn/low/*.jpg');
}
}
else {
$files=glob('pages/section1/dn/low/*.jpg');
}
break;
case 'section2':
//the same like in section 1, path is .../section2/...
break;
case section3:
//the same like in section 1, path is .../section3/...
break;
default:
//the same like in section 1
break;
}
else {
//the same like in section 1
}
경로 D = 독일어, E = 영어, C = 체코 어, P = 가격, N = noprices
__All__이 코드는'$ files = glob ('pathto ......');로 재 작성 될 수 있습니다. 당신은'pathto'가 url 매개 변수에 의존하는 방법을 설명해야합니다. –
이 내 코드에 대한 경로를 추가했습니다. –