Solving common problems with PHP

不言
Release: 2023-03-24 08:00:02
Original
3388 people have browsed it

The content of this article is about solving common problems in PHP. It has certain reference value. Now I share it with everyone. Friends in need can refer to it.

Questions

Display Chinese garbled characters?

Solution

Modify the source file to UTF-8 format.

Question

Uncaught Error: Cannot use string offset as an array in...

Cause

The array to be written does not exist and needs to be created

$arrays = $array();
Copy after login
Copy after login

Problem

Set$_SESSION The variable is in Does the page disappear after jumping?

Solution

You need to call session_start(); # every time you use $_SESSION

##Question

  • After using

    AJAX to access the server, a ?## is added at the end of the URL in the URL bar.

  • #Open
  • chrome

    and press F12 to enter the source code. After setting the breakpoint, the program does not jump to the breakpoint but restarts. refresh page?

Solution

When using the form, you need to use:

Copy after login
Copy after login

This format, if modified to:

Copy after login
Copy after login

will cause the above situation!

Question

PHP

The JSON format data sent to JS, JS When parsing using JSON.parse(), chrome prompt:

Uncaught SyntaxError: Unexpected token ? in JSON at position 0
    at JSON.parse ()
    at XMLHttpRequest.xmlhttp.onreadystatechange (download.php:84)
Copy after login
Copy after login

Cause

File format error

Solution

Due to the background

PHP

file, use:

require_once "../utils/config.php";
Copy after login
Copy after login
contains other files, and the file of this file The format is:

UTF-8

with BOM, you need to use Ultra Edit to save the file as UTF-8 format without BOM!

Question

Display Chinese garbled characters?

Solution

Modify the source file to

UTF-8

format.

Question

Uncaught Error: Cannot use string offset as an array in...

Cause

The array to be written does not exist and needs to be created

$arrays = $array();
Copy after login
Copy after login

Problem

Settings

$_SESSION

Variables disappear after page jump?

Solution

You need to call

session_start();

# every time you use $_SESSION ##Question

After using
    AJAX
  • to access the server, a

    ?## is added at the end of the URL in the URL bar. #Open

    chrome
  • and press
  • F12

    to enter the source code. After setting the breakpoint, the program does not jump to the breakpoint but restarts. refresh page?

    Solution

When using the form, you need to use:

Copy after login
Copy after login
This format, if modified to:

Copy after login
Copy after login

will cause the above situation!

Question

PHP The

JSON

format data sent to JS, JS When parsing using JSON.parse(), chrome prompt:

Uncaught SyntaxError: Unexpected token ? in JSON at position 0
    at JSON.parse ()
    at XMLHttpRequest.xmlhttp.onreadystatechange (download.php:84)
Copy after login
Copy after login
Cause

File format error

Solution

Due to the background PHP file, use:

require_once "../utils/config.php";
Copy after login
Copy after login

contains other files, and the file of this file The format is: UTF-8 with BOM, you need to use

Ultra Edit

to save the file as UTF-8 format without BOM! Related recommendations:

Summary of common PHP interview questions

Detailed explanation of common PHP algorithms or functions

The above is the detailed content of Solving common problems with PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!