LTrim and RTrim in PHP to remove the left and right spaces and special character instances _php skills

Source: Internet
Author: User
Tags rtrim

This article analyzes the use of LTrim and RTrim in PHP to remove the left and right spaces and special characters. Share to everyone for your reference, specific as follows:

The definition of LTrim in PHP is as follows:

LTrim (String,charlist)

Parameter description:

String required. Specify the string to check.

Charlist
Optional. Specify which characters to remove from the string. If this argument is omitted, all of the following characters are removed:
"" "-NULL
"\ T"-tab
"\ n"-line Wrap
"\X0B"-Vertical tab
"\ r"-Carriage return
""-Space

Second, the PHP RTrim definition as follows:

RTrim (String,charlist)

The parameter description is as follows:

String required. Specify the string to check.

Charlist
Optional. Specify which characters to remove from the string. If omitted, all of the following characters are removed:
"" "-NULL
"\ T"-tab
"\ n"-line Wrap
"\X0B"-Vertical tab
"\ r"-Carriage return
""-Space

Three, the usage example is as follows:

<?php
$str = "(: @_@ Yun-Habitat community to provide a large number of excellent scripts and materials for readers to download \ n \ @_@:)  ";
 Echo LTrim ($STR);
 echo "<br>";
 Echo LTrim ($str, "(: @_@");
 echo "<br/>";
 echo RTrim ($STR);
 echo "<br>";
 Echo RTrim ($str, "@_@:) ");
? >

The results of the operation are as follows:

(: @_@ Cloud Communities provide a wealth of excellent scripts and materials for readers to download @_@:) 
Cloud Communities provide a wealth of excellent scripts and materials for readers to download @_@:) 
(: @_@ Cloud Communities provide a wealth of excellent scripts and materials for readers to download @_@:)
(: @_@ The cloud-dwelling community provides a wealth of good scripts and materials for readers to download 

I hope this article will help you with the PHP program design.

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.