php method to remove special characters: 1. The trim function can remove the first and last symbols; 2. The ltrim function removes the special symbols on the left, which is the beginning of the string; 3. The rtrim function removes the symbols on the right side of the string, which is the string. symbol behind.
How to remove special characters in php:
We have three functions, namely [trim
】, 【 ltrim
】, 【rtrim
】.
1. First, let’s take a look at the actual usage of trim
.
trim
Remove the first and last symbols
string trim(string $str[,string $charlist])
$str="happy\n";//此时必须用双引号 var_dump(trim($str));
Commonly used special symbols include \t
,\n
,\r
,\o
,\xOB
How to remove other symbols please see the code below
$str="happy@";//此时可以用单引号 var_dump(trim($str,'@'));
2,ltrim
It is to remove the special symbols on the left, which is the beginning of the string.
$str="\nhappy";//此时必须用双引号 var_dump(ltrim($str));
General symbols
$str="@happy";//此时可以用单引号 var_dump(trim($str,'@'));
3, rtrim
Remove the symbols on the right side of the string, that is, the symbols at the end of the string.
The usage of rtrim is the same as that of ltrim
The above is the usage of the beginning and the end. If we want to remove the middle symbol, we need to use str_replace.
str_replace
: Yes String replacement
Example
$str="hap\npy"; var_dump(str_replace("\n","",$str));
This is an array if there are multiple symbols
$str=" hap\np y"; var_dump(str_replace(array(" ","\n",)'',$str));
Related learning recommendations:PHP programming from entry to proficiency
The above is the detailed content of How to remove special characters in php?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
