thinkphp網(wǎng)站開發(fā)之分頁參數(shù)亂碼解決

2023-02-16    分類: 網(wǎng)站建設(shè)

網(wǎng)站導(dǎo)航

網(wǎng)站開發(fā)中經(jīng)常會(huì)遇到整站搜索功能,而搜索之后會(huì)出現(xiàn)大量的數(shù)據(jù),而通常都是使用分頁的形式去展示這些數(shù)據(jù),當(dāng)搜索的字段中含有中文時(shí),就可能導(dǎo)致翻頁出現(xiàn)亂碼,導(dǎo)致翻頁失效。
搜索使用form表單提交的方式,前端代碼:
<form class="" method="get" action="{:urlrotue('Search/index')}">
<div class="header-form">
<input type="text" class="header-text" name="q" id="q" placeholder="請(qǐng)輸入搜索關(guān)鍵詞">
<a><input type="submit" class="header-sub" value=""></a>
</div>

</form>
頁面URL地址
程序代碼
下面是頁碼出現(xiàn)亂碼的地址,點(diǎn)擊后無法跳轉(zhuǎn)到第二頁的內(nèi)容:
PHP代碼
查看了ThinkPHP\Library\Think\Page.class文件后發(fā)現(xiàn)代碼是這樣的
PHP代碼2
然后只需要這樣修改:
private function url($page){
return str_replace(urlencode('[PAGE]'), $page, $this->url);
}
$request_url = $_SERVER["REQUEST_URI"];
if(!preg_match("/\/p\/\d+/", $request_url)) {
$request_url = str_replace(".html", '/p/'.urlencode('[PAGE]').'.html', $request_url);
}
$this->url = preg_replace("/\/p\/\d+\.html/", '/p/'.urlencode('[PAGE]').'.html', $request_url);

得到的正常的地址應(yīng)該是這樣的:

在后續(xù)的使用過程中又發(fā)現(xiàn),URL在Apache上是/不會(huì)有問題,但是在IIS上用/會(huì)亂碼,必須用?=這種格式才行或者到需要通過url?=傳遞參數(shù)時(shí)。
$this->parameter[$this->p] = '[PAGE]';
$paramStr="";
foreach($this->parameter as $key => $value){
$paramStr = $paramStr.'&'.$key.'='.$value;
}
$paramStr = substr($paramStr,1,strlen($paramStr));
$this->url = U(ACTION_NAME).(strpos(U(),"?")?'&':'?').$paramStr;

得到的地址是這樣的:

網(wǎng)站欄目:thinkphp網(wǎng)站開發(fā)之分頁參數(shù)亂碼解決
網(wǎng)頁鏈接:http://www.muchs.cn/news12/237462.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、服務(wù)器托管網(wǎng)站策劃、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)