Home  >  Article  >  Backend Development  >  How to solve the problem of garbled characters when passing parameters from js to php

How to solve the problem of garbled characters when passing parameters from js to php

小云云
小云云Original
2018-03-31 15:51:411947browse

This article mainly shares with you how to solve the garbled problem of passing parameters from js to php. It is mainly shared in the form of code. I hope it can help everyone.

This problem can be solved from two aspects:

Start with escape(), encodeURL(), encodeURIComponent() from js, and use php to receive it directly without processing

From php, you can urldecode when writing it into js and taking it out.

Related knowledge

The escape encoding of js is: %u4E2D%u56FD; the unescape decoding of js
js The (encodeURI after encoding is: %E4%B8%AD%E5%9B%BD; js’s decodeURI decoding
php’s urlencode is encoded as: %D6%D0%B9%FA; php’s urldecode decoding

Example:

js:

window.location.href="<?php echo site_url(&#39;mail_controller/sendMailEn&#39;).&#39;/&#39;;?>
"+encodeURIComponent($("username").value)+&#39;/&#39;+encodeURIComponent($("mobile").value);

php:

<?php $this->email->message(urldecode($username).&#39;预定了房间!我的电话号码是&#39;.urldecode($moblie));   ?>

Related recommendations:

How to solve php garbled code

The above is the detailed content of How to solve the problem of garbled characters when passing parameters from js to php. For more information, please follow other related articles on the PHP Chinese website!

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