다음 코드는 주로
이와 같은 다른 사이트의 URL에서 흔히 볼 수 있는
검색 엔진입니다.
http://www.xxx.com/module/show/action/list/page/7
또는
확장자가 있는 http://xx.com/module/show/action/show/id/8.shtml 또는
http://xx.com/module/show/action/show/id/8?word=ss&age=11
오늘은 이 메소드의 구현을 발표하겠습니다. 가장 간단한 코드 함수는 클래스로 캡슐화되지 않습니다. 주로 함수를 사용하는 것이 더 편리하기 때문입니다
.
/**
* 친숙한 URL 액세스를 얻으세요
*
* @accesspublic
* @return 배열
*/
함수 getQueryString(){
$_SGETS = 폭발("/",substr($_SERVER['PATH_INFO'],1));
$_SLEN = 개수($_SGETS);
$_SGET = $_GET;
for($i=0;$i<$_SLEN;$i+=2){
if(!empty($_SGETS[$i]) && !empty($_SGETS[$i+1])) $_SGET[$_SGETS[$i]]=$_SGETS[$i+1];
}
$_SGET['m'] = !empty($_SGET['m']) && is_string($_SGET['m']) ? Trim($_SGET['m']).'Action' : 'indexAction';
$_SGET['a'] = !empty($_SGET['a']) && is_string($_SGET['a']) ? Trim($_SGET['a']) : '실행';
$_SGET 반환;
}
/**
* 링크 URL 생성
*
* @accesspublic
* @param 배열 $arr
* @return 문자열
*/
함수 setUrl($arr){
글로벌 $글로벌;
$queryString='';
if($Global['urlmode']==2){
foreach($arr $k=> $v){
$queryString.=$k.'/'.$v.'/';
}
}
$queryString.=$Global['urlsuffix'];
$queryString을 반환합니다.
}
?>
사용이 매우 간단합니다.
<?php
$_GET= getQueryString();
?>
하지만 이것만으로는 충분하지 않습니다. 오직 달성만 가능합니다.
http://www.xxx.com/index.php/module/show/action/list/page/7 중간에 index.php가 추가로 있어서 삭제하고 다시 작성해야 합니다. 일부 파일은 그렇지 않습니다. 예를 들어 스타일 사진 등을 원한다면
RewriteEngine
조건에서 .htaccess 파일을 생성하십시오.
RewriteCond $1 !^(index.php|css|pics|themes|js|robots.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
이제 괜찮습니다. 지금 가서 테스트해 보세요.
<?php
$_GET= getQueryString();
print_r($_GET);
?>