Reputation: 2855
I have a set of strings. Their values can be different from string to string. Here is an example of three strings:
$string1 = "505";
$string2 = "500";
$string3 = "601";
I need to remove the second 0 only yielding:
$string1 = "55";
$string2 = "50";
$string3 = "61";
I have tried substr
, str_replace
and ltrim
but cannot produce my desired results. Ideas?
Upvotes: 1
Views: 3156
Reputation: 83
You can use
$string = substr($string,0,1).substr($string,-(strlen($string)-2));
Upvotes: 0
Reputation: 78994
Combine substr
and str_replace
and you get substr_replace
:
$string1 = substr_replace($string1, '', 1, 1);
Upvotes: 7