I have a string $str = "4sX3yY4mj2DT9gVOOS0x60onT08lwzLLZBqn8"
.
Now I want to remove the first 5 numeric characters from the string.
How do I do that in php?
In PHP to remove characters from beginning we can use ltrim but in that we have to define what we want to remove from a string i.e. removing characters are to be known. $str = "geeks" ; // Or we can write ltrim($str, $str[0]); $str = ltrim( $str , 'g' );
One useful function that can be used to remove special characters from a string is the str_replace() function. The empty string must be used to the replace character in this function to remove the specified character. The syntax of this function is given below. The str_replace() function can take four arguments.
Use the limit parameter with preg_replace:
$str = preg_replace('~\d~', '', $str, 5);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With