PHP string Important functions

Source: Internet
Author: User

1, Chop ()

Remove a character from the right end of a string

Chop (string,charlist)

$str= "Hello world~"; Echo Chop ($str, "ld~");  // Hello wor

PS. charlist parameter is optional, if not, the default is to remove

    • "+"-NULL
    • "\ T"-tab
    • "\ n"-line break
    • "\X0B"-Vertical tab
    • "\ r"-Enter
    • ""-Space

2, Chunk_split ()

Splits a string into a series of smaller parts.

Chunk_split (String,length,end)

$str= "Hello world~"; Echo Chunk_split ($str, 1, ".");  // H.E.L.L.O. w.o.r.l.d.~.

3, Explode ()

Breaks the string into arrays.

Explode (Separator,string,limit)

$str= "beijing,shanghai,nanjing,tianjing,anqing"; Print_r (explode(",",$str, 3));     // Array ([0] = Beijing [1] = Shanghai [2] = nanjing,tianjing,anqing)

PS. Limit optional, which specifies the number of array elements returned.

4, Htmlspecialchars ()

Converts a pre-defined character to an HTML entity.

Htmlspecialchars (String,flags,character-set,double_encode)

$str= "Hello <em>world</em>~"; Echo Htmlspecialchars ($str);       // Hello <em>world</em>~
    • & (and number) becomes &
    • "(double quotes) becomes"
    • ' (single quote) become '
    • < (less than) becomes <
    • > (greater than) becomes >

5, implode ()//alias Join ()

Returns a string that is composed of array elements.

Implode (Separator,array)

$arr=array("shanghai,nanjing,beijing,tianjing,anqing"); Echo implode ("",$arr);    // shanghai,nanjing,beijing,tianjing,anqing

PS. separator is optional. Specifies what is placed between the elements of the array. The default is "" (an empty string).

6, Lcfirst ()

Converts the first character in a string to lowercase.

Lcfirst (String)

$arr= "Hello World"; echo lcfirst ($arr);   // Hello World

PHP string Important functions

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.