For an experienced PHP programmer, it is no longer a difficult task to implement the query function of a string. Here we will introduce a PHP query string shortcut techniques for your reference.
A deep understanding of PHP plug-in mechanism principle
Explore PHP variable parsing order How to get submit data
A thorough understanding of PHP operating mechanism
Simple analysis of PHP function extract () application technique
Summarize some PHP information functions for you
RL transfer variables are commonplace for programmers, and many people think this article is nothing new. The way we pass a variable through a URL is called a Get method, and the other is the Post method. Both of these methods are very easy to implement in PHP. For example, suppose you are ready to make a database query, you need to pass three variables through get: City, ID, and paid.
The traditional PHP query string method constructs the query string as in the following example:
* Assume we want to pass this
variables * * *
$city _name = "New York";
$invoice _id = 3456;
$paid = 1;
$query _string = "city={$city _name}
&id={$invoice _id}&paid={$paid}";
$url .
$query _string;
Most PHP developers today are accustomed to this approach. It has no problem with only three or four variables, but when you add variables, the code becomes difficult to understand and maintain, and it's easy to introduce subtle errors.
The best way to pass a get variable is through the Http_build_query function introduced in PHP5, which receives an array parameter, returns a properly formatted, URL-encoded string that can be spliced directly into the URL. The following is an example of the corresponding PHP query string.
$city _name = "New York";
$invoice _id = 3456;
$paid = 1;
$fields = Array (' City ' => $city _name,
' id ' => $invoice _id,
' paid ' => $paid);
$url
. Http_build _query ($fields, "&");