Monday, September 5, 2022

[FIXED] How to remove the leading character from a string?

Issue

I have a input string like:

$str = ':this is a applepie :) ';

How can I remove the first occurring : with PHP?

Desired output: this is a applepie :)


Solution

To remove every : from the beginning of a string, you can use ltrim:

$str = '::f:o:';
$str = ltrim($str, ':');
var_dump($str); //=> 'f:o:'


Answered By - Haim Evgi
Answer Checked By - Terry (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.