


How to solve the problem of php outputting pictures and displaying Chinese garbled characters
Solution to php outputting pictures and displaying Chinese garbled characters: 1. Add ob_clean() before the PHP code to clear the buffer; 2. Set UTF-8 encoding.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of php output pictures And the problem of Chinese garbled characters is displayed?
php uses the GD image library to draw the output image and the problem of garbled characters and the solution to the problem of garbled Chinese characters on the picture
Source code:
<html> <head> <title>PHP 图像测试</title> </head> <body> <?php #创建背景图像 $im = @imagecreate(500,500) or die("没有安装GD图像库<br>"); #设置背景颜色 $bgCol=imagecolorallocate($im,255,0,0); #设置字体颜色 $texCol=imagecolorallocate($im,255,255,0); $motto = "I love my baby! 我家宝贝聪明可爱漂亮"; $motto = iconv("gb2312", "utf-8", $motto); #在背景图像上输入文字 imagestring($im,3,5,5,$motto,$texCol); #输出图像 header("Content-Type: image/png"); imagepng($im); #清除所有资源 imagedestroy($im); ?> </body> </html>
Results obtained after running :
<html> <head> <title>PHP ͼ������</title> </head> <body> �PNG IHDR���M�PLTE���lۜ�IDATx���1 �0�ᔀ]*��W�:/�ر��C����ɥ��1N���?^������M��c��N���>t1�+�w�1 �Z۷�+��<��7���y�ݏ�.�}�T�ݧ_��?�/o�m��IEND�B`�</body> </html>
(1) Solution: Add ob_clean(); in front of $im = @imagecreate(500,500) or die("GD image library is not installed
"); to clear the buffer first . The picture can be displayed, but the text on the picture can only display English and numbers, and Chinese characters will be garbled.
(2) The default English encoding of imagestring only supports UTF-8, so Chinese characters will be garbled. You should use
imagettftext($im,10,30,0,100,$texCol,"c:/windows/fonts/simhei.ttf",$motto);
"c:/windows/fonts/simhei.ttf", the system automatically With black body.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the problem of php outputting pictures and displaying Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
