Συνάρτηση ltrim() του PHP
Παράδειγμα
Αφαίρεση χαρακτήρων από την αριστερή πλευρά της αλφαριθμητικής αλυσίδας:
<?php $str = "Hello World!"; echo $str . "<br>"; echo ltrim($str,"Hello"); ?>
Ορισμός και χρήση
Η συνάρτηση ltrim() αφαιρεί λύσεις κενών χαρακτήρων ή άλλων προκαθορισμένων χαρακτήρων από τη δεξιά πλευρά της αλφαριθμητικής αλυσίδας.
Συσχετιζόμενες συνάρτησεις:
Γλώσσα
ltrim(αλφαριθμητική αλυσίδα,charlist)
Παράμετρος | Περιγραφή |
---|---|
αλφαριθμητική αλυσίδα | Απαιτείται. Ορίζει την αλφαριθμητική αλυσίδα που πρέπει να ελεγχθεί. |
charlist |
Optional. Specifies which characters to remove from the string. If this parameter is omitted, the following characters are removed:
|
Technical Details
Return Value: | Returns 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 "Not using ltrim: " . $str; echo "<br>"; echo "Use ltrim: " . ltrim($str); ?>
The HTML output of the above code (please view the source code):
<!DOCTYPE html> <html> <body> Not using ltrim: Hello World!<br>Use ltrim: Hello World! </body> </html>
The browser output of the above code:
Not using ltrim: Hello World! Use ltrim: Hello World!
Example 2
Remove newline characters from the left side of the string (\n):
<?php $str = "\n\n\nHello World!"; echo "Not using ltrim: " . $str; echo "<br>"; echo "Use ltrim: " . ltrim($str); ?>
The HTML output of the above code (please view the source code):
<!DOCTYPE html> <html> <body> Not using ltrim: Hello World!<br>Use ltrim: Hello World! </body> </html>
The browser output of the above code:
Not using ltrim: Hello World! Use ltrim: Hello World!