Home >Backend Development >PHP Problem >How to remove the tab space character at the beginning of the string in php

How to remove the tab space character at the beginning of the string in php

青灯夜游
青灯夜游Original
2022-04-22 19:11:092434browse

In PHP, you can use the ltrim() function to remove the tab blank character at the beginning of the string. The syntax is "ltrim(string)"; when only one parameter is passed to the ltrim() function, it is used to specify When you want to check a string, you can delete the whitespace characters (such as spaces, tabs, newlines, etc.) at the beginning of the string.

How to remove the tab space character at the beginning of the string in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use ltrim () function to remove the tab space character at the beginning of the string.

ltrim() function removes whitespace characters or other predefined characters at the beginning of a string.

White space characters include: spaces, tabs, newlines and other white space characters.

ltrim() function accepts two parameters:

ltrim(string,charlist)
##ParametersDescriptionRequired. Specifies the string to check.
string
charlist Optional. Specifies which characters are removed from a string.

If this parameter is omitted, all the following characters are removed:


    "\0" - NULL
  • "\t" - tab tab Character
  • "\n" - Line feed
  • "\x0B" - Vertical tab character
  • "\r" - Carriage return
  • " " - Space
Return value: Returns the modified string.

Example: Remove the tab blank character (tab character) at the beginning of the string

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
$str1 = "	Hello World!";
$str2 = "\tHello World!";
echo "处理前的字符串:";
var_dump($str1);
var_dump($str2);

echo "处理后的字符串:";
var_dump(ltrim($str1));
var_dump(ltrim($str2));
?>

How to remove the tab space character at the beginning of the string in php

Recommended study: "

PHP video tutorial

The above is the detailed content of How to remove the tab space character at the beginning of the string in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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