search
HomeBackend DevelopmentPHP Tutorial为什么有的页面乱码,为什么有的乱码不乱码?有点晕

请看这两个页面:http://www.qgren.com/qigong/gongfa/15_30.shtml
摘要出现乱码。

再看这个页面:http://www.qgren.com/qigong/gongfa/15_28.shtml
摘要没有乱码,很正常。

在网站,部分页面正常,部分页面摘要乱码。我有点晕。
程序是dedecms,gbk版本。我网页模板也是gbk。

调用摘要的代码如下:
{dede:field.description runphp='yes'}
if(@me'' )@me = '

摘要:'.@me.'

 ';
{/dede:field.description}

不知道谁能解我疑惑,为什么会这样?


回复讨论(解决方案)

无余没、无余欲 後有特殊字符。
?查一下。

被加入了空格,删掉即可
观察到 meta 中是一样的乱码,所以就从 meta 中取了

$t = get_meta_tags('http://www.qgren.com/qigong/gongfa/15_30.shtml');echo '乱码:', $s = $t['description'], PHP_EOL;echo '还原:', str_replace(' ', '', $s);
乱码:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲? 5敝?侨耸そ?煌恕N宜当巳宋?そ?帧W苑侨缋础4硕?屑洹K?芟ぶ?J枪省0⒛选D?锪咳巳硕? H松瞥锪咳巳硕? H顺锪咳巳恕
还原:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲荆当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而龋人善筹量人人而玻人筹量人人

虽然看到的是所谓的空格,但也可能是某个汉字的变异
所以请核对文字后告知差异

被加入了空格,删掉即可
观察到 meta 中是一样的乱码,所以就从 meta 中取了

$t = get_meta_tags('http://www.qgren.com/qigong/gongfa/15_30.shtml');echo '乱码:', $s = $t['description'], PHP_EOL;echo '还原:', str_replace(' ', '', $s);
乱码:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲? 5敝?侨耸そ?煌恕N宜当巳宋?そ?帧W苑侨缋础4硕?屑洹K?芟ぶ?J枪省0⒛选D?锪咳巳硕? H松瞥锪咳巳硕? H顺锪咳巳恕
还原:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲荆当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而龋人善筹量人人而玻人筹量人人



文字差异:
还原:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲荆当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而龋人善筹量人人而玻人筹量人人

文字:阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲 尽。当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而 取。人善筹量人人而病。人筹量人人

找到共同规律,都是一个字后接一个句号。
版主看看

无余没、无余欲 後有特殊字符。
?查一下。


无余没、无余欲  后面并没有特殊字符,见文档。后面是   尽。
无余灭、无余没、无余欲尽。当知是人胜进不退。

$t = get_meta_tags('http://www.qgren.com/qigong/gongfa/15_30.shtml');$s = $t['description'];$n = strpos($s, '欲')+2;$t = substr($s, $n);echo bin2hex('尽。当'), PHP_EOL;echo bin2hex($t), PHP_EOL;$n = strpos($s, '而')+2;$t = substr($s, $n);echo bin2hex('取。人'), PHP_EOL;echo bin2hex($t), PHP_EOL;echo str_replace(' ', "\xa1\xa1", $s), PHP_EOL;echo bin2hex(' '); //再看看全角空格
bea1a1a3b5b1be20a3b5b1d6aacac7c8cbcaa4bdf8b2bbcdcba1a3ced2cbb5b1cbc8cbceaacaa4bdf8b7d6a1a3d7d4b7c7c8e7c0b4a1a3b4cbb6fed3d0bce4a1a3cbadc4dccfa4d6aaa1a3cac7b9caa1a3b0a2c4d1a1a3c4aab3efc1bfc8cbc8cbb6f8c820a3c8cbc9c6b3efc1bfc8cbc8cbb6f8b220a3c8cbb3efc1bfc8cbc8cba1c8a1a1a3c8cbc820a3c8cbc9c6b3efc1bfc8cbc8cbb6f8b220a3c8cbb3efc1bfc8cbc8cba1阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲尽。当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而取。人善筹量人人而病。人筹量人人?a1a1

很显然,你在处理文字时做了将全角空格替换成半角空格的处理
这就是问题的根源!

$t = get_meta_tags('http://www.qgren.com/qigong/gongfa/15_30.shtml');$s = $t['description'];$n = strpos($s, '欲')+2;$t = substr($s, $n);echo bin2hex('尽。当'), PHP_EOL;echo bin2hex($t), PHP_EOL;$n = strpos($s, '而')+2;$t = substr($s, $n);echo bin2hex('取。人'), PHP_EOL;echo bin2hex($t), PHP_EOL;echo str_replace(' ', "\xa1\xa1", $s), PHP_EOL;echo bin2hex(' '); //再看看全角空格
bea1a1a3b5b1be20a3b5b1d6aacac7c8cbcaa4bdf8b2bbcdcba1a3ced2cbb5b1cbc8cbceaacaa4bdf8b7d6a1a3d7d4b7c7c8e7c0b4a1a3b4cbb6fed3d0bce4a1a3cbadc4dccfa4d6aaa1a3cac7b9caa1a3b0a2c4d1a1a3c4aab3efc1bfc8cbc8cbb6f8c820a3c8cbc9c6b3efc1bfc8cbc8cbb6f8b220a3c8cbb3efc1bfc8cbc8cba1c8a1a1a3c8cbc820a3c8cbc9c6b3efc1bfc8cbc8cbb6f8b220a3c8cbb3efc1bfc8cbc8cba1阿难。有犯戒。彼于心解脱、慧解脱如实知。彼于所起犯戒无余灭、无余没、无余欲尽。当知是人胜进不退。我说彼人为胜进分。自非如来。此二有间。谁能悉知。是故。阿难。莫筹量人人而取。人善筹量人人而病。人筹量人人?a1a1

很显然,你在处理文字时做了将全角空格替换成半角空格的处理
这就是问题的根源!



还是有点乱码,人筹量人人 ?。多了一个怪异的东东。

我把你这段代码试过了,有点纳闷,纳闷的是
echo str_replace(' ', "\xa1\xa1", $s);
这段代码后面不输出东西, ?,这个怪异的东东就不会出现。
反之,只要后面输出什么,比如你的代码,输出个PHP_EOL, ?就出现了。
真的好奇怪啊
Statement
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
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in LaravelNotifications in LaravelMar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)