String operations in PHP (1)

黄舟
Release: 2023-03-04 06:46:01
Original
1382 people have browsed it

1. String connector

The half-width symbol "." is the string connector, which can connect two or more strings into one string. For example:

Copy after login

The running result is: PHP Chinese website: m.sbmmt.com

2. Remove spaces and special characters at the beginning and end of the string

When users enter data, they often enter extra spaces unintentionally. In some cases, In this case, spaces and special characters are not allowed in the string. In this case, the spaces and special characters in the string must be removed.

2.1 trim() function

trim() function is used to remove spaces at the beginning and end of a string, and returns the current string with spaces removed.

Syntax format: string trim(string str [,string charlist]);

The parameter str of the trim() function is the string object to be operated, and the parameter charlist is an optional parameter, specifying that it needs to be deleted from the pending string Specific characters. If this parameter is not set, all optional characters will be deleted. The optional values ​​of parameter charlist are as follows:

Parameter value/description

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!