Other PHP garbled issues and dirname (_ file __)

Source: Internet
Author: User

Code: <HTML>
<Head>
<Title> test </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
</Head>
<? PHP

$ A = 'dir C: '; // note: the key on the left of keyboard 1 is used to output information about drive C.
Echo $;

?>
<Body> </body>
</Html>

Symptom: All Chinese characters after running are garbled, but they are displayed normally in the source file.

Solution: Set <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
The UTF-8 in is changed to gb2312 and the display is normal. In case of garbled characters, do not change the encoding mode of the browser to see if it is normal. If it is normal, change the webpage to the corresponding encoding mode.
Or modify the PHP Code as follows:
<? PHP

$ A = 'dir C :';

$ B = mb_convert_encoding ($ A, 'utf8', 'gb2312 ');

Echo $ B;

?>
This problem can also be solved by converting the encoding before the output.
 

About _ file _: (Note: there are two underlines. It is easy for beginners to see the error. As a result, use of undefined constant _ file _-assumed '_ file _' is incorrect, and garbled characters appear .)

Explanation:The complete file path and file name (including the suffix ). If it is used in a include file, the include file name is returned. Starting from PhP 4.0.2, __file _ always contains an absolute path, while earlier versions sometimes contain a relative path.

String dirname (string path)

Explanation:Returns a string containing a full path pointing to a file. This function returns the directory name after removing the file name (including the suffix.

Note:In Windows, both slash (/) and backslash (/) can be used as Directory separators. It is a slash (/) in other environments (/).

What if we use dirname for nesting?

Dirname (_ file __));
Assume that _ file _ Is/wwwhome/web/config. php.
The above method output is/wwwhome/Web
Dirname (_ file _); the directory name at the top of the file is obtained.
Dirname (_ file _); the directory name of the file's layer is obtained.

Summary: As we all know, after entering dir in DOS, the folder list and file list will be listed. If the parameter in dirname function is the folder name, it will also be processed. that is to say, you can use this function to obtain the upper-level directories of the current directory.

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.