PHP: String to array, array to string, string intercept, replace, find

Source: Internet
Author: User
Tags array to string explode

Array of string turns
$str = ' One|two|three|four ';p rint_r (Explode (' | '), $STR); Explode string to array

$str = ' one three ';       Str_split is divided into bits $arr1 = Str_split ($STR), $arr 2 = Str_split ($str, 3);p Rint_r ($arr 1);p Rint_r ($arr 2);

Print as follows:
Array ( [0] = = o [1] = n [2] = + E [3] = = [4] = [5] = w [6] = = O [7] [8] [+] = [ 9] = h [ten] = R [One] ~ + e [+] + e) Array ( [0] = = One [1] = tw [2] = O T [3] = = HRE [4] = = e)
Array to String
Inplode ()
String interception
The substring method is used to extract the character of a string intermediary between two specified subscripts
SUBSTRING (start,end)
The Substr method is used to return a substring of the specified length starting at the specified position.
SUBSTR (start [, length])
Replace
Str_replace ()
Replace the character "world" in the string "Hello world!" with "Shanghai":
echo Str_replace ("World", "Shanghai", "Hello world!");
Preg_replace: Perform a search and replace of a regular expression
Find
Preg_match ();
Preg_grep ();

PHP: String to array, array to string, string intercept, replace, find

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.