PHP some common string functions

Source: Internet
Author: User
This article introduces some of the commonly used string functions in PHP, here to share to you, you can also give a friend in need a little reference, let's take a look at it

1. Get string length strlen ()


2. Remove blank string trim (), LTrim (), RTrim () to remove whitespace from the end of the string, the beginning of the string, and the ending of the string.

Trim (), LTrim (), RTrim () function delete the characters by default:

symbols ASCII code meaning
“ ” 0x20 Space
"\ T" 0x09 Tabs
"\ n" 0X0A Line break
"\ r" 0x0D Carriage return character
"The" 0x00 Null character
"\X0B" 0x0B Portrait tab


Examgle$title = "  programming php  \ n"; $str 1 = LTrim ($title);//promgromming php \n$str2 = RTrim ($title);//  Programming Php$str3 = Trim ($title);//programming PHP
You can use the trim () function with parameters to remove the opening or closing whitespace without deleting the tab $record = "fred\tflintstone\t35\twilma\t  \ n"; $record = Trim ($record, "\r\n\ 0\x0b ");//The record value at this time is:" Fred\tflintstone\t35\twilma\t "

Change the case

Strtolower (), Strtoupper () operation of the entire string

Ucfirst () only the first character of a string, Ucwords () the first character of each word in the action string

EXAMPLE$STR1 = "FRED fintstone"; $str 2 = "Barney Rubble";p rint (Strtolower ($str 1));p rint (Strtoupper ($str 1));p rint ( Ucfirst ($str 2));p rint (Ucwords ($str 2));
Output Fred Fintstonefred Fintstonebarney Rubblebarney Rubble
Related Article

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.