The string format of PHP

Source: Internet
Author: User
Tags control characters explode rtrim string format
1. Collation of Strings: Chop (), Itrim (), Trim ()

The trim () function is used to organize user input data, as shown below:

$name =trim ($name);

$email =trim ($email);

The Tirm () function can remove spaces from the start and end of a string and return the resulting string. By default, the line break (n) Carriage return (R) horizontal (t) and vertical tab (X0B) string end symbols () and spaces are stripped.

The following is from the manual

Without the second parameter, RTrim () to the strip these characters:

* "" (ASCII (0x20)), an ordinary space.
* "T" (ASCII 9 (0x09)), tab.
* "N" (ASCII (0x0A)), a new line (line feed).
* "R" (ASCII (0x0D)), a carriage return.
* "" (ASCII 0 (0x00)), the Nul-byte.
* "x0b" (ASCII (0x0b)), a vertical tab

Example#1 Usage Example of RTrim ()
<?php

$text = "Ttthese are a few words:) ... ";
$binary = "X09example stringx0a";
$hello = "Hello World";
Var_dump ($text, $binary, $hello);

Print "n";

$trimmed = RTrim ($text);
Var_dump ($trimmed);

$trimmed = RTrim ($text, "t.");
Var_dump ($trimmed);

$trimmed = RTrim ($hello, "Hdle");
Var_dump ($trimmed);

Trim the ASCII control characters in the end of $binary
(from 0 to inclusive)
$clean = RTrim ($binary, "x00.") x1f ");
Var_dump ($clean);

?>

The example above will output:

"These are a few words:) ... "
String (Example) string
"
String (one) "Hello World"

"These are a few words:) ..."
String "These are a few words:)"
String (9) "Hello Wor"
String "Example string"

function explode () implode () join ()

explode-use a string to split another string

Ordering of Strings strcmp () strcasecmp () strnatcmp ()

Find a string in a string strstr () STRCHR () strrchr () Stristr ()

Too much, read the handbook slowly.

<
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.