Home > Backend Development > PHP Problem > How to solve the problem of garbled characters when turning pages in PHP

How to solve the problem of garbled characters when turning pages in PHP

藏色散人
Release: 2023-03-12 21:22:02
Original
1583 people have browsed it

Solution to garbled page turning in php: 1. Open the paging code written in php; 2. Add the code "".

How to solve the problem of garbled characters when turning pages in PHP

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

#How to solve the problem of garbled characters when turning pages in PHP?

Specific problem description:

php paging garbled characters. The paging code written in php displays garbled characters on the web page.

The paging code is as follows. What is displayed on the web page is: 鏄剧ず绗� 0-0 鉉¤褰曪纴鍏� 鏉¤褰�. Such garbled code appears.

<?php
include("conn.php");
function _PAGEFT($totle,$displaypg=20,$url=&#39;&#39;){
global $page,$firstcount,$pagenav,$_SERVER;
$GLOBALS["displaypg"]=$displaypg;
if(!$page)
$page=1;
if(!$url){
$url=$_SERVER["REQUEST_URI"];
}
$parse_url=parse_url($url);
$url_query=$parse_url["query"];
if($url_query){
$url_query=ereg_replace("(^|&)page=$page","",$url_query);
$url = str_replace($parse_url["query"], $url_query, $url);
if ($url_query)
$url .= "&page";
else
$url .= "page";
} else {
$url .= "?page";
}
$lastpg = ceil($totle / $displaypg); //最后页,也是总页数
$page = min($lastpg, $page);
$prepg = $page -1; //上一页
$nextpg = ($page == $lastpg ? 0 : $page +1); //下一页
$firstcount = ($page -1) * $displaypg;
$pagenav = "显示第 <B>" . ($totle ? ($firstcount +1) : 0) . "</B>-<B>" . min($firstcount + $displaypg, $totle) . "</B> 条记录,共 $totle 条记录";
if ($lastpg <= 1)
return false;
$pagenav .= " <a href=&#39;$url=1&#39;>首页</a> ";
if ($prepg)
$pagenav .= " <a href=&#39;$url=$prepg&#39;>前页</a> ";
else
$pagenav .= " 前页 ";
if ($nextpg)
$pagenav .= " <a href=&#39;$url=$nextpg&#39;>后页</a> ";
else
$pagenav .= " 后页 ";
$pagenav .= " <a href=&#39;$url=$lastpg&#39;>尾页</a> ";
$pagenav .= " 到第 <select name=&#39;topage&#39; size=&#39;1&#39; onchange=&#39;window.location=\"$url=\"+this.value&#39;>\n";
for ($i = 1; $i <= $lastpg; $i++) {
if ($i == $page)
$pagenav .= "<option value=&#39;$i&#39; selected>$i</option>\n";
else
$pagenav .= "<option value=&#39;$i&#39;>$i</option>\n";
}
$pagenav .= "</select> 页,共 $lastpg 页";
}
?>
Copy after login

Solution:

Add

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
Copy after login

in front of the top

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to solve the problem of garbled characters when turning pages in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template