Category Archives: PHP

[Solved] ini_set(“display_errors”,”On”); & error_reporting(E_ALL);

When using PHP to do website development, in order to prevent users from seeing error messages, the unfriendly interface appears. Therefore, it is generally set in php.ini:

display_ errors = Off;
However, sometimes we need to open error messages during development. At this time, you can set the following in the PHP file:

ini_ set("display_errors","On");
error_ reporting(E_ ALL);

However, sometimes we can’t display the syntax errors in PHP even if we set it like this in time

solution:
suppose there are syntax errors in this PHP file.
you can create a new test.php and edit it in this PHP as follows:
ini_ set(“display_ errors”,”On”);
error_ reporting(E_ ALL);
include (“target file”)

error_ reporting(“E_All “) and ini_set(“display_errors” and “on”),  What is the difference?

If the latter is off, the former is useless even for e-all

How to Solve Soapserver Error: ”looks like we got no XML document“

 

Due to the version problem, there may be an error in uncaught soapfault exception: [Client] looks like we got no XML document. One of the reasons is that when sending and receiving, a warning is sent together with the data, resulting in a format error

When I used PHP to write soapserver, I couldn’t get the return value correctly. I found several solutions on the Internet, but they didn’t work until someone reminded me that there was something wrong with the data sent, so I could select the data manually

Rewrite

classSoapClientNewextendsSoapClient
{
publicfunction__doRequest($request,$location,$action,$version,$one_way=0)
{
$request=parent::__doRequest($request,$location,$action,$version,$one_way);

$start=strpos($request,'<soap');//Do the processing according to the actual situation.... , if it starts with <?xml, change it to <?xml
$end=strrpos($request,'>');
returnsubstr($request,$start,$end-$start+1);
}
}

Call

$client=newSoapClientNew($url);

can solve the problem

add a few lines to the code,

classSoapClientNewextendsSoapClient
{
publicfunction__doRequest($request,$location,$action,$version,$one_way=0)
{
$request=parent::__doRequest($request,$location,$action,$version,$one_way);

$myfile=fopen("newfile.txt","w")ordie("Unabletoopenfile!");
$txt=$request;
fwrite($myfile,$txt);
fclose($myfile);

$start=strpos($request,'<?xml');//Do the processing according to the actual situation.... , if it starts with <?xml, change it to <?xml
$end=strrpos($request,'>');
returnsubstr($request,$start,$end-$start+1);
}
}

it can be found that the data to be sent generated by the function becomes

<br/>
<b>Deprecated</b>:Automaticallypopulating$HTTP_RAW_POST_DATAisdeprecatedandwillberemovedinafutureversion.Toavoidthiswarningset'always_populate_raw_post_data'to'-1'inphp.iniandusethephp://inputstreaminstead.in<b>Unknown</b>online<b>0</b><br/>
<br/>
<b>Warning</b>:Cannotmodifyheaderinformation-headersalreadysentin<b>Unknown</b>online<b>0</b><br/>
<?xmlversion="1.0"encoding="UTF-8"?>
<SOAP-ENV:Envelopexmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:ns1="http://localhost/zlf/server.php"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:sayhelloResponse><returnxsi:type="xsd:string">hello!zlfamazing</return></ns1:sayhelloResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

the front warning is the cause of soap error. In addition to appeal settlement, follow the prompts to add always in php.ini file_ populate_ raw_ post_ If the semicolon in front of data = - 1 is removed and warning disappears, the problem of error reporting can also be solved

PHP: How to Solve Laravel rules preg_match(): No ending delimiter ‘/’ found

### Instructions to
solve php-Laravel preg_match(): No ending delimiter’/’ found

1. The reason for
the problem is normally added as follows

1
2
3
4
5
6
public function rules()
{
    return [
        'domain'=>'required|regex:/^[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA-Z]+$/'
    ];
}

 

Then when I tested the interface, I found that it kept reporting errors:

php-Laravel preg_match(): No ending delimiter’/’ found

Second, the solution is to
change the code to this

public  function rules()
{
    return [
         'domain'=>['required','regex:/^[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-]+\.[a-zA- Z]+$/' ]
    ];
}

 

Then it’s normal

 

PHP Curl: How to Sending Post JSON Formate Data

$data = array(“name” => “Hagrid”, “age” => “36”);

$data_string = json_encode($data);

$ch = curl_init(‘http://api.local/rest/users’);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);

curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(

‘Content-Type: application/json’,

‘Content-Length: ‘ . strlen($data_string))

);

$result = curl_exec($ch);

curl_close();

 

get  $GLOBALS[“HTTP_RAW_POST_DATA”];

 

How to Solve PHP Error: Function name must be a string

 

PHP low level error: function name must be a string technology

In my impression, this kind of PHP error is rarely encountered, but once encountered, all of a sudden still can not find the problem

When a person is very tired in the process of development, he makes a low-level mistake. He looks at the screen and doesn’t know why, so the whole network looks for the answer. PHP error: function name must be a string appears in the following code

<?php

$_GET('name');

$_POST('name');

$_COOKIE('name');

?>

Function name and method name must be a string, which is easy to mislead people. PHP 5.3 has started to support anonymous functions, and variables can also be used as functions

 

[Solved] Primary script unknown in nginx configuration PHP

Cause

In the past two days, when building the virtual host, the environment is basically configured. There is no problem in accessing the HTML file, but there is a file not found error when accessing the PHP file

Solution

When there is a problem, first open the log to find the error message

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

Well, if you don’t understand it, you can go directly to Baidu, and then according to the various results of Baidu, the attempt is failed, such as this one

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
change to
SCRIPT_FILENAME $document_root$fastcgi_script_name; 

But my nginx configuration file is already like this, and then I started to compare the nginx configuration of the server running normally with my current nginx configuration. After comparison, the two are the same, so the problem is not nginx

Then continue to search by chance, try all kinds of things, and finally find a solution

/etc/selinux/config  mid
SELINUX=enforcing
to
SELINUX=disabled

If it hasn’t been solved, consider the issue of permissions

It’s over

If problems are not solved, they will come back again

<?php
  echo 'How can't this input box be removed?';

PHP regular matching H1 datagram error preg_ match(): Unknown modifier ‘h’ in

Question:

$str = "<h1>this is test msg</h1>";
$ruler = "/^<h1>(.*?)</h1>$/";
$res = preg_match($ruler,$str,$v);
var_dump($v);

Error:
Warning: preg_match(): Unknown modifier 'h' in /usr/local/var/www/test.php on line 36
NULL

Why is it wrong?The reason is because of my delimiter

in regular rules, the/do delimiter is used, while in </ h1> There are also /, so such errors will be reported

Solution:

1. Will < h1> I’d like to change it to </ h1> It’s OK

$ruler = "/^<h1>(.*?)<\/h1>$/";

2. Change the delimiter

[How to Solve] for the right syntax to use near ”X”

BUG:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”4” at line 1

SELECT a.*,b.user_nickname, b.user_head_url from qk_user_album a, qk_user b where a.album_user_id = b.user_id ORDER BY a.album_create_date desc LIMIT 0, ‘4’;

Filename: D:\DEV_PHP\WAMP\www\qk\system\database\DB_driver.php

Line Number: 330

 

Problem solved.

Here the limit syntax is used, the two parameters should be numbers, should not appear string

The reason is that when PHP pass the parameters, the second parameter is not converted, add an intval function, string to number can be

[PHP Error]Only variables should be passed by reference

PHP Error: Only variables should be passed by reference

A PHP Error was encountered  
Severity: Runtime Notice  
Message: Only variables should be passed by reference  

$file_name = $_FILES[$upload_name][‘name’];
$file_extension = end(explode(‘.’, $file_name)); //ERROR ON THIS LINE

Reason for error reporting:

Getting the suffix name with the end function points the internal pointer of the array to the last element, while end is a reference to pass the value。

The problem is, that end requires a reference, because it modifies the internal representation of the array (i.e. it makes the current element pointer point to the last element).

The result of explode(‘.’, $file_name) cannot be turned into a reference. This is a restriction in the PHP language, that probably exists for simplicity reasons.

The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Solution:

(1) Define a variable to get the value after explode, then use the end function to:

$parts = explode('.', $file_name);  
$file_extension = end($parts);  

(2) Use substr and strrchr functions to get the file suffix:

$ext = substr( strrchr($file_name, '.'), 1);  

(3) Use the pathinfo function to get the file suffix:

$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);  

The end() function points the internal pointer of the array to the last element and returns the value of that element, if successful

 

PHP Update failed (The zip extension and unzip command are both missing, skipping

unzip dependency

Exception message: Unzip with unzip command failed, falling back to ZipArchive class

Explanation: The php-zip extension relies on the unzip command and fails to unzip the archived zip file, causing a rollback to the archive.

Workaround: Install zip, the unzip command, and the php-zip extension

#centos (I'm using php7.1, as an example) yuminstallzip unzip php7.1-zip #ubuntu apt-getinstallzip unzip php7.1-zip