Home >Backend Development >PHP Tutorial >Solving common problems with PHP

Solving common problems with PHP

不言
不言Original
2018-04-17 13:49:163625browse

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();

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:

<form>
    <label>控制器调试助手:</label>
    <input type="button" name="submit_xghelper" value="下载"  onclick="onDownloadButtonClick(&#39;XGHelper&#39;)"></form>

This format, if modified to:

<form>
    <label>控制器调试助手:</label>
    <button onclick="onDownloadButtonClick(&#39;XGHelper&#39;)">下载</button></form>

will cause the above situation!

Question

PHP

The JSON format data sent to JS, JS When parsing using JSON.parse(), chrome prompt: <pre class="brush:php;toolbar:false;">Uncaught SyntaxError: Unexpected token ? in JSON at position 0 at JSON.parse (&lt;anonymous&gt;) at XMLHttpRequest.xmlhttp.onreadystatechange (download.php:84)</pre>

Cause

File format error

Solution

Due to the background

PHP

file, use: <pre class="brush:php;toolbar:false;">require_once &quot;../utils/config.php&quot;;</pre> 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();

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:

<form>
    <label>控制器调试助手:</label>
    <input type="button" name="submit_xghelper" value="下载"  onclick="onDownloadButtonClick(&#39;XGHelper&#39;)"></form>
This format, if modified to:

<form>
    <label>控制器调试助手:</label>
    <button onclick="onDownloadButtonClick(&#39;XGHelper&#39;)">下载</button></form>

will cause the above situation!

Question

PHP The

JSON

format data sent to JS, JS When parsing using JSON.parse(), chrome prompt: <pre class="brush:php;toolbar:false;">Uncaught SyntaxError: Unexpected token ? in JSON at position 0 at JSON.parse (&lt;anonymous&gt;) at XMLHttpRequest.xmlhttp.onreadystatechange (download.php:84)</pre>Cause

File format error

Solution

Due to the background PHP file, use:

<pre class="brush:php;toolbar:false;">require_once &quot;../utils/config.php&quot;;</pre>

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!

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