PHP can divide the string into an array, and also can be connected to the string, and the exact connection of the array elements into a string, with these two functions we can be between the array and the string of free conversion, see the example of the text below.Implode () Join function:This function implements connecting an array element to a string, before we give it two arguments, one is the connector that is going to be connected to the arrayNote is a one-dimensional array oh, the multi
Array explode (string $ separator, string $ string [, int $ limit])
This function has three parameters. The first parameter $ separator sets a delimiter (string ). The second parameter $ string specifies the string to be operated. The $ limit parameter is optional and specifies the maximum number of substrings to be split.This function returns an array composed of split substrings.
Let's take a look at the example below to analyze a multi-line text da
First look at the definition of two methods:
Function prototype: Array split (String $pattern, string $string [, int $limit])
Function prototype: array explode (string $separator, string $string [, int $limit])
At first glance there is no difference, it seems that the function is the same. I made this mistake. Note that the first parameter of the two function is string $pattern and string separator, one is the $pattern description is a regular s
Explode cut the foreach loop output, and add a condition containing a certain character to not output this group
$ Navinfor [down] = 'AAA $ http: // $ ccc $ ddd '; $ downzu = explode ("$ ", $ navinfor [down]); foreach ($ downzu as $ k = >$ v) {$ downno = $ k + 1; echo $ downno. '='; echo $ v.'';}
The output is
1 = aaa
2 = ccc
3 = ddd
If the condition contains http, no output is cleared.
Array explode (string $ separator, string $ string [, int $ limit])
This function has three parameters. The first parameter $ separator sets a delimiter (string ). The second parameter $ string specifies the string to be operated. The $ limit parameter is optional and specifies the maximum number of substrings to be split.This function returns an array composed of split substrings.
Let's take a look at the example below to analyze a multi-line text da
Split supports regular expressions
========================================================== ==============
The explode function can only be separated by characters. However, the split function uses regular expressions. Of course, the split function can be used to handle some complex string analysis problems. Explode requires certain rules.
Appendix:
PHP explode
Substr (STR, start, length );
Example: substr ('php is very good language );
Output is ve;
If the length of Start> STR is returned ();
Substr ('php is very good language );
Substr ('php is very good language ',4);
Output as (blank)
Output is V (It indicates that both start and langth are 4)
When start is a negative value, it starts to read from the end of STR (* at this time, it starts to read from-1 rather than from 0 ),
Substr ('php is very good language );
Output as uage
The simplest use of explode
In this case, we'll split the string into arrays:
The code is as follows
Copy Code
$STR = "Hello World". It ' s a beautiful day. ";Print_r (Explode ("", $str));?>Output:Array([0] => Hello[1] => world.[2] => It ' s[3] => a[4] => Beautiful[5] => day.)
But if you run into the following function, how do we solve the "acne, Acne Printing # antio
First, let's take a look at the definitions of the two methods:Function prototype: array split (string $ pattern, string $ string [, int $ limit])Function prototype: array explode (string $ separator, string $ string [, int $ limit])There is no difference at first glance, and it seems that all functions are the same. I made this mistake. Note that the first parameters of the two functions are string $ pattern and string separator. $ pattern indica
Explode (symbols, characters)
The characters processed by explode will eventually be saved in an array form, so let's take a look at an example below.
$t = ' 9,133, Dan County ^14,203, Changsha ^14,206, Hengyang ';
$ar = Explode (', ', $a);
Print_r ($ar);
It has to be print_r, and if echo only outputs the array,
The results are as follows:
Array([0] => 9,1
For the use of the PHP split string explode function, using the EXPLODE function to split the string into an array, here is a summary of a few examples that need a friend to refer to.
PHP array and explode function application examples, for everyone to learn the reference.
Example 1:
?
1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15
Example 2:
Array explode (string $separator, string $string [, int $limit])
The function has 3 parameters, and the first parameter $separator sets a split character (string). The second parameter $string specifies the string to manipulate. The $limit parameter is optional, specifying the maximum number of substrings to be split into.This function returns an array of separated substrings.
Look at the example below to analyze a comma-delimited line of text data.
Use of PHP explode function, this is my own use of explode
if (!empty ($CT)) {
if (Strpos ($ct, "|") ===false) {
mysql_query ($sql) or Die (Mysql_error ());
Exit (" ");
}else{
$ex =explode ("|", $CT);
for ($i =0; $i
$r =mysql_query ("select * from FFFF where zddd= '". $ex [$i]. "");
if (!mysql_fetch_array ($r)) {
mysql_query (INSERT into Rwerew (f_idff
We encountered some problems when using split today. I still do not have a deep understanding of the function. I will make a mark in the close-up. First, let's look at the definitions of the two methods:
Function prototype: array split (string $ pattern, string $ string [, int $ limit])
Function prototype: array explode (string $ separator, string $ string [, int $ limit])
There is no difference at first glance, and it seems that all function
Split string
Using the explode function to split a string into an array
Copy CodeThe code is as follows:
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separate strings by commas
$hello = Explode (', ', $source);
for ($index =0; $index
{
echo $hello [$index];echo]
";
}
?>
Split function for character segmentation
The delimiter can be a slash, a dot, or a horizontal line
Copy CodeThe code
How does the explode function convert a string into a multi-dimensional array? For example, I now have a string
$ Str = id @ 2title ** Me and You @ url ** http://baidu.com % id @ 3title ** Me and You 3 @ url ** http: // baidu. com3 % id @ 4title ** Me and You 4 @ url ** http: // baidu. com4
How to convert such a string into a multi-dimensional array.
Array (
[0] => array (
Id => 2
Title => Me and You
Url => http://baidu.com
)
[1] => array (
Id => 3
Ti
This article describes how php splits strings into arrays using The explode () function, which has some reference value. For more information, see the following example () the function splits a string into an array. Share it with you for your reference. The specific analysis is as follows:
Explode () function: splits a string into an array.
The sample code is as follows:
"; Print_r ($ arr);?>The resu
There are some problems with split today. Or the function is not deeply understood, close-up to make a mark
First look at the definition of two methods:
Function prototype: Array split (String $pattern, string $string [, int $limit])
Function prototype: array explode (string $separator, string $string [, int $limit])
At first glance there is no difference, it seems that the function is the same. I made this mistake. Note that the first parameter
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.