Some minor problems with PHP coding

Source: Internet
Author: User

Recently on the SAE to write microblogging applications, encountered some minor problems, write down, for reference:

1. Error prompt:

Fatal Error:can ' t use function return value in write context  

The reason for the problem is very simple, $_get, $_post, such as the predefined variable is an array is not a function, if you use $_get ("paramname") such a method to get the parameter will encounter this error, the correct practice is to use square brackets: $_get[' paramname '].

2. How to transfer Chinese between Ajax and PHP programs:

2.1, Ajax to submit Chinese data to the PHP program, my Web page using UTF-8 encoding, request to submit before I use the jquery serialization function to the request parameters have been processed (before this aspect of processing is to request the parameter string to do two encodeURI processing, This function of jquery greatly simplified this work):

var paramdata=$ (' #formID '). Serialize ();  

After the request is submitted, the UrlDecode function is used to do one processing to get the correct UTF-8 Chinese code:

$paramValue=urldecode($_get["paramname"]);   

If the page is GBK encoded, it seems like to use the Iconv function to do one more step.

2.2, the PHP program to the Ajax script to return to the Chinese language is more simple, add a set encoding the header can be: because I use the UTF-8 code, so add the following:

Header (' Content-type:text/html;charset=utf-8 ');   

Some minor problems with PHP coding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.