Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of garbled codes in url by php

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "php how to solve the problem of garbled codes in url". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let's let the editor take you to learn "how to solve the problem of garbled codes in url" by php.

Php to solve the problem of garbled url parameters: 1, the use of urlencode and urldecode functions for transcoding; 2, through the "iconv (" gb2312 "," UTF-8 ", $gonghui);" way of transcoding.

This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.

How does php solve the problem of garbled url parameters in Chinese?

Php url address column transfer Chinese garbled solution set

Php address column sends Chinese $_ GET after garbled, urlencode and urldecode usage are explained in detail.

Url coding

Syntax: string urlencode (string str)

Return value: string

Function types: coding processing

For example:

The code is as follows:

Url decoding

Restores the URL encoded string.

Syntax: string urldecode (string str)

Return value: string

Function types: coding processing

For example:

Process and display the previously transmitted Chinese.

The code is as follows:

On the problem of Chinese garbled codes obtained from url by php using get method

Use $gonghui = iconv ("gb2312", "UTF-8", $gonghui); another method code

/ * * multibyte string encoding conversion function * * @ param string str string that needs to be converted * @ param string to_encoding is specified to be converted to a certain encoding, such as gb2312, gbk, utf-8, etc. * @ param mixed from_encoding mixes to specify the encoding of the original string For example, specify JIS, eucjp-win, sjis-win mixed coding * @ return stringstring mb_convert_encoding (stringstr, string to_encoding [, mixed from_encoding]) * * / at the same time

The mb_convert_encoding function is a multi-byte string encoding conversion function within php, which can support almost all encodings when needed. PHP > = 4.0.6, 5 versions are supported.

Directly get reg.php?gh= xxx

/ / Union login reference $gonghui = $_ GET ['gh']

The obtained $gonghui is encoded by gb2312 and output to the utf-8 web page to display garbled codes.

Change to

/ / Union login parameters $gonghui = $_ GET ['gh']; $gonghui = mb_convert_encoding ($gonghui, "UTF-8", "gb2312")

It shows that it is normal.

Convert the entire page

This method is suitable for all coding environments. In this way, all the character sets other than the first 128 characters (display characters) are represented by NCR (Numeric character reference, such as "Chinese characters" will be converted into "Chinese characters"). This kind of coding can be displayed normally in any coding environment.

Add the following three lines to the header of the php file:

The code is as follows:

Mb_internal_encoding ("gb2312"); / / the gb2312 here is the original mb_http_output of your website ("HTML-ENTITIES"); ob_start ('mb_output_handler')

To use the mb_convert_encoding function, you need to enable PHP's mbstring (multi-byte string) extension.

If there is no mbstring extension that does not have php enabled, you need to make the following settings for php to support the extension.

1. Windows server environment

Edit the php.ini file to remove and restart the web server in front of extension=php_mbstring.dll.

2. Linux server environment

Add the-- enable-mbstring=cn compilation parameter when compiling the configuration, and then compile and install PHP.

The third reference method for other netizens:

/ / method-urldecode$url = 'aaa.php?region='.urldecode ("Sichuan Province")

Unlock the other page using base64_decode

Base64_decode ($region) / / method 3: let the server support Chinese [root@dhcp ~] # localelang=zh_cn.utf-8lc_ctype= "zh_cn.utf-8" lc_numeric= "zh_cn.utf-8" lc_time=clc_collate=clc_monetary= "zh_cn.utf-8" lc_messages= "zh_cn.utf-8" lc_paper= "zh_cn.utf-8" lc_name= "zh_cn.utf-8" lc_address= "zh_cn.utf-8" lc_telephone= "zh_ Cn.utf-8 "lc_measurement=" zh_cn.utf-8 "lc_identification=" zh_cn.utf-8 "lc_all= [root @ dhcp ~] # so far I believe that you have a deeper understanding of "php how to solve the problem of Chinese parameter garbled in url". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report