PHP explode of function usage shard the string

  • 2020-05-26 07:53:14
  • OfStack

 
<? 
// ###  Shard string  #### 
function jb51netcut($start,$end,$file){ 
$content=explode($start,$file); 
$content=explode($end,$content[1]); 
return $content[0]; 
} 
?> 


Definition and usage of explode
The explode() function splits a string into an array.

grammar
explode(separator,string,limit)

parameter describe separator A necessity. Specifies where to split the string. string A necessity. The string to be split. limit Optional. Specifies the maximum number of array elements to return.
instructions
This function returns an array of strings, each element of which is a substring separated by separator as a boundary point.

The separator parameter cannot be an empty string. If separator is an empty string (""), explode() returns FALSE. If the value contained by separator is not found in string, explode() returns an array containing the individual elements of string.

If the limit parameter is set, the array returned contains up to limit elements, and the last element will contain the rest of string.

If the limit parameter is negative, all elements except the last -limit element are returned. This feature is new to PHP 5.1.0.
Hints and comments
Note: the parameter limit was added in PHP 4.0.1.

Note: for historical reasons, implode() can accept both parameter orders, but explode() cannot. You must make sure that the separator parameter precedes the string parameter.

example

In this example, we will split the string into an array:
 
<?php 
$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.
)

Related articles: