String processing of PHP learning notes

Source: Internet
Author: User
Tags explode strcmp

Blog posted on 2016 0531.11:30

Handling of strings

A summary of some of the methods that may be used is mainly:

First common words

1.strlen () string length

$a = "HI"; echo strlen ($a);

The result is 2.

2.STRCMP () string comparison, case-sensitive, same return 0

Var_dump (strcmp ("Hello", "Hello")); The result is int1.

Var_dump (strcmp ("A", "B")); The result is int-1.

3,STRCASECMP () string comparison, case insensitive, same return 0,

Echo strcasecmp ("A", "a"); The returned result is int 0

4. Strtolower () Turn lowercase

$a =app

echo strtolower ($a); The result is an app

5,strtoupper () Turn capital,

echo strtoupper ($a);

Ditto for the opposite meaning

6.explode () split string, split into array (returns an array)

$a = "N01XN02XN03XN04;"

$attr =explode ("x", $a); X is a separator

Var_dump ($ATTR);

The result is:

Array (size=4)

0=>string ' No1 ' (lenght=3)

1=>string ' NO2 ' (lenght=3)

2=>string ' NO3 ' (lenght=3)

3=>string ' No4 ' (lenght=3)

* The use of the more common

Example database 1 content Lookup

2 answers to the question selection questions

7,implode () stitching array elements into a string

$a = "N01/n02/n03/n04"

Implode (">", $attr)

The result is n01>n02>n03>n04.

8. Substr_replace (string,replacement,start,length) * Replace string, replace specified position

Substr_replace ($a, "xx", 0,4) replaces the contents of the specified position with "XX"

9 Str_replace (find,replace,string) replaces some characters in a string with other characters

Find replacements

Echo Str_replace ("n", "M", $a);

Replace All "n" in $ A with "M"

Ten substr () intercept characters

Subsre ($a, 0,4) intercepts characters from $ A 0 in length lenght=4

$STR = array

(

Array ("n001", "Han"),

Array ("n002", "Hui"),

Array ("n003", "Miao")

);

$a = "n001^ han |n002^ hui |n003^ miao Nationality |";

Echo substr ($a, 0,strlen ($a)-1);

Regular expressions

Arrays and data structures in PHP

String processing of PHP learning notes

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.