Home >Backend Development >PHP Tutorial >Solving common problems with PHP
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
AJAX to access the server, a
?## is added at the end of the URL in the URL bar.
and press F12
to enter the source code. After setting the breakpoint, the program does not jump to the breakpoint but restarts. refresh page?
When using the form, you need to use:
<form> <label>控制器调试助手:</label> <input type="button" name="submit_xghelper" value="下载" onclick="onDownloadButtonClick('XGHelper')"></form>
This format, if modified to:
<form> <label>控制器调试助手:</label> <button onclick="onDownloadButtonClick('XGHelper')">下载</button></form>
will cause the above situation!
QuestionPHP
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 (<anonymous>)
at XMLHttpRequest.xmlhttp.onreadystatechange (download.php:84)</pre>
File format error
SolutionDue to the background
PHP file, use: <pre class="brush:php;toolbar:false;">require_once "../utils/config.php";</pre>
contains other files, and the file of this file The format is:
with BOM, you need to use Ultra Edit to save the file as UTF-8
format without BOM!
Display Chinese garbled characters?
SolutionModify the source file to
UTF-8 format.
Uncaught Error: Cannot use string offset as an array in...
The array to be written does not exist and needs to be created
$arrays = $array();Problem
Settings
$_SESSION Variables disappear after page jump?
You need to call
session_start(); # every time you use
$_SESSION
##Question
After using
?## is added at the end of the URL in the URL bar. #Open
to enter the source code. After setting the breakpoint, the program does not jump to the breakpoint but restarts. refresh page?
When using the form, you need to use: <form>
<label>控制器调试助手:</label>
<input type="button" name="submit_xghelper" value="下载" onclick="onDownloadButtonClick('XGHelper')"></form>
This format, if modified to:
<form> <label>控制器调试助手:</label> <button onclick="onDownloadButtonClick('XGHelper')">下载</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 (<anonymous>)
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 "../utils/config.php";</pre> contains other files, and the file of this file The format is: UTF-8
with BOM, you need to use
to save the file as UTF-8 format without BOM! Related recommendations:
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!