Computer >> 컴퓨터 >  >> 프로그램 작성 >> PHP

PHP 시작 부분에서 추가 공백을 제거하시겠습니까?

<시간/>

처음부터 여분의 공백을 제거하려면 PHP에서 ltrim()을 사용하십시오. 다음이 우리의 변수라고 가정해 봅시다 -

$value="  Hello, welcome to PHP Tutorial  ";

우리는 왼쪽에 공백이 없는 출력을 원합니다 -

Hello, welcome to PHP Tutorial

예시

<!DOCTYPE html>
<html>
<body>
<?php
   $value="  Hello, welcome to PHP Tutorial  ";
   print_r( "The actual value is=".$value."<br>");
   echo "The actual length is=",strlen($value)."<br>";
   $modifiedValue=ltrim($value);
   echo "After removing extra whitespace from beginning=",strlen($modifiedValue)."<br>";
   echo "The result is=".$modifiedValue;
?>
</body>
</html>
입니다.

출력

그러면 다음과 같은 출력이 생성됩니다.

The actual value is= Hello, welcome to PHP Tutorial
The actual length is=34
After removing extra whitespace from beginning=32
The result is=Hello, welcome to PHP Tutorial