PHP BASIC Programming FAQ Summary

Source: Internet
Author: User
Tags php error phpinfo
This post was last edited by phpnewnew on 2012-02-02 18:33:34

This version of the FAQ, limited to the length of the answer may not be exhaustive, need more answers to make full use of the search engine.
The content of this post will be updated and added gradually. Want to be able to help more needs of the novice, if there are errors please correct me.

1. How to determine if PHP is installed successfully, and output the relevant configuration environment parameters of PHP?
A: 1. Create a new PHP file, such as file name: phpinfo.php
2. Add code to the PHP file

3. Open this file in the browser, localhost/phpinfo.php
If the normal appearance of a detailed document then the installation succeeds, if the output of the above source directly or prompt to download the file as unsuccessful.

2. How do I turn on PHP error notification? Default is off state
Answer: php.ini File search field error_reporting modified to error_reporting = E_all
Display_errors modified to Display_errors = On If there is a # in front of the field please delete this comment symbol.
You need to restart Apache to take effect. You can also add code error_reporting (e_all) to the PHP file;

3. A similar "notice:undefined index:xxx in ..." appears The error message
A: This is a new change after the 5.3 (if not mistaken) version, this is not an error, just a hint.
Tip content is used if the variable is not declared.
The workaround can be:
A. Turn off the error prompt (or modify the error level). Reference FAQ 2 Modify display_errors = Off
B. Add if (Issset ($_post[' test ')) to determine the arguments before the submitted parameters such as $_post[' test '], other
Variable hints can be substituted with initialization assignments. For example $test = ';

4. The database or page output is garbled, but there is no problem with the English and the numbers.
A: Generally, this problem is caused by coding, so keeping all coding consistent is the solution to the problem.
Taking GBK as an example
PHP File Header Output header ("content-type:text/html; CHARSET=GBK ");
PHP links the database after executing mysql_query ("SET NAMES ' GBK '");
Database/table encoding set to GBK
Whether the file encoding check is ANSI

5. How to build PHP operating environment?
A: We will have a detailed post to introduce this aspect of the content, if you are just beginning to learn the students recommend you use the integration
installation package to learn, because the PHP version is more so if only to refer to the online textbooks can easily lead to learning confusion.
Please download the complete installation package for the appropriate system below to run the installation and configuration issues, please refer to the official Help documentation.

Windows:http://www.apachefriends.org/zh_cn/xampp-windows.html
Linux:http://www.apachefriends.org/zh_cn/xampp-linux.html

6. Why do I see some code that uses You can, and you don't need it.
A: There is a short mark in the PHP.ini option, open can Short_open_tag = on Remember if the previous # please delete this comment symbol.
This feature is not recommended for individuals, please follow The way to write code.

7. What are the common PHP development tools?
A: If you like the development tools that look professional and versatile
Eclipse Zendstudio Phpdesinger phpstorm NetBeans ...
If you like plain, primitive development tools
Notepad notepad++ editplus ....
Linux is basically listed above the IDE has, simple to use vim Gvim ...

8. The phenomenon of "supernatural" appears in the process of floating-point arithmetic?
Answer: Warning
Floating point Accuracy
It is obvious that a simple decimal score like 0.1 or 0.7 cannot be converted to an internal binary format without losing a little bit of precision. This can result in confusion: for example, floor ((0.1+0.7) *10 typically returns 7 instead of 8 as expected because the internal representation of the result is actually similar to 7.9999999999 ....
This is related to the fact that it is impossible to accurately express certain decimal fractions with a finite number of digits. For example, the decimal 1/3 becomes 0.3333333. . .。
So never believe that the floating-point number is accurate to the last one, and never compare two floating-point numbers for equality. If you do need a higher precision, you should use any mathematical or GMP function with any precision.

9.utf8 encoded file Session_Start (), header (), Settcookie () and other functions error, prompting "headers already sent".

A: UTF8 encoding the usual editor will be in the header of the file with a three-byte BOM encoding to identify the UTF8 encoding format, which three bytes is not visible to the normal file editor, and output to the first HTML output. The above error is indicated when you execute the above function. Workaround: Use EditPlus, etc. can clear the BOM editor, clear the BOM (set to UTF8 clear BOM) save it.

10.mysql and PHP coding should be noted in one place.
A: Need to remind everyone is MySQL SET NAMES ' UTF8 ', here is no horizontal bar, and PHP is the correct wording is UTF-8, many beginners in this place easy to confuse and puzzled, I hope to pay special attention to this small difference.


Reply to discussion (solution)

Read, study, thank you brother Niu

Support a bit. Niuniu hasn't had a holiday yet!

Support a bit. Niuniu hasn't had a holiday yet!

Nes Nous face not to work, why come to holiday? hahaha

Early see this post is good hehe

To learn the list of all the problems I have seen AH hehe

The last one really did not know, study ....

Good for the novice, thank you.

See the last one, remember when I was hurt, fortunately, behind the use of the notepad++ editor, there is UTF8 to clear the BOM function

Ten years later, it feels different to see these problems.

Learned, thank you.

Oh. Once again the knowledge of the temperature. Thank you!

Question 9th
What if we use Notepad?
Don't want to use EditPlus OH

Well organized, thank you for sharing.

Question 9th
What if we use Notepad?
Don't want to use EditPlus OH
What do you do without this function?

These problems have been basically met

Study, I just came to the students Oh ·

Study, want to find a PHP development tool

Very useful

Back then constantly Google degree Niang, Nei noodles AH

Ah ah, all is the foundation, study!

Learning, something to gain.

Common, very classic questions.

Thank you! Beginners must look!

Learn to learn, thanks to moderators

Study of the study

Look.....

Very good, some problems have been in the heart doubts, but did not find the answer, today finally puzzled Anext

As if the Nineth article was wrong. A function name Settcookie () should be Setcookie (), I'm a beginner, I don't know if that's right.

If this is the first question I have the Apache installed it works can also be PHP files cannot run why did solve it

Novice learning, understanding a bit difficult.

Support, very useful

4. The database or page output is garbled, but there is no problem with the English and the numbers.
A: Generally, this problem is caused by coding, so keeping all coding consistent is the solution to the problem.
Taking GBK as an example
PHP File Header Output header ("content-type:text/html; CHARSET=GBK ");
PHP links the database after executing mysql_query ("SET NAMES ' GBK '");
Database/table encoding set to GBK
Whether the file encoding check is ANSI
Correct, database/table encoding is not set to GBK also can, because there is the previous set names GBK this statement, MySQL will automatically help you convert. Of course, the database/table encoding must be and GBK have a conversion relationship with the code such as Gb2312,utf8.

To update the request.

Good post, huh?

  • 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.