PHP ltrim() ফাংশন

প্রদত্ত উদাহরণ

স্ট্রিং এর বামদিকের চার্যাকরণ সরিয়ে দেয়

<?php
$str = "Hello World!";
echo $str . "<br>";
echo ltrim($str,"Hello");
?>

Run Instance

সংজ্ঞা ও ব্যবহার

ltrim() ফাংশন স্ট্রিং এর বামদিকের শূন্য স্পেস বা অন্য প্রকার প্রিডিফাইন্ড চার্যাকরণ সরিয়ে দেয়

সংশ্লিষ্ট ফাংশনসমূহ:

  • rtrim() - স্ট্রিং এর ডানদিকের শূন্য স্পেস বা অন্য প্রকার প্রিডিফাইন্ড চার্যাকরণ সরিয়ে দেয়
  • trim() - স্ট্রিং এর দুই পাশের শূন্য স্পেস বা অন্য প্রকার প্রিডিফাইন্ড চার্যাকরণ সরিয়ে দেয়

ব্যবহারিক কাঠামো

ltrim(string,charlist)
পারামিটার বর্ণনা
string অপরিহার্য।পরীক্ষা করতে হলে চিহ্নিত স্ট্রিং
charlist

Optional. Specify which characters to remove from the string. If this parameter is omitted, the following characters will be removed:

  • "\0" - NULL
  • "\t" - Tab
  • "\n" - New Line
  • "\x0B" - Vertical Tab
  • "\r" - Carriage Return
  • " " - Space

Technical Details

Return Value: Return the modified string.
PHP Version: 4+
Update Log: In PHP 4.1, a new feature was added: charlist Parameter.

More Examples

Example 1

Remove spaces from the left side of the string:

<?php
$str = "    Hello World!";
echo "Do not use ltrim: " . $str;
echo "<br>";
echo "Use ltrim: " . ltrim($str);
?>

The HTML output of the above code (please check the source code):

<!DOCTYPE html>
<html>
<body>
Do not use ltrim:    Hello World!<br>Use ltrim: Hello World!
</body>
</html>

The browser output of the above code:

Do not use ltrim: Hello World!
Use ltrim: Hello World!

Run Instance

Example 2

Remove newline characters from the left side of the string (\n):

<?php
$str = "\n\n\nHello World!";
echo "Do not use ltrim: " . $str;
echo "<br>";
echo "Use ltrim: " . ltrim($str);
?>

The HTML output of the above code (please check the source code):

<!DOCTYPE html>
<html>
<body>
Do not use ltrim:
Hello World!<br>Use ltrim: Hello World!
</body>
</html>

The browser output of the above code:

Do not use ltrim: Hello World!
Use ltrim: Hello World!

Run Instance