Question

I would like to always delete the character in the 2nd position within a string. The trouble is, this could literally be anything.

Sample inputs would be:

5H23098
SHISL
S-SLSYNSL
M/SHGIKT

Output should be:

523098
SISL
SSLSYNSL
MSHGIKT
Was it helpful?

Solution

$str = "ASDFGH";
echo substr_replace($str, "", 1, 1);

OTHER TIPS

$s1 = $str[0];
$s2 = substr($str, 2);

$result = $s1.$s2;

$s = substr($s,0,1).substr($s,2);

Also it's possible to do:

$str = 'abcd';
$str[1] = '';

But take into the account that

strlen($str) == 4
$string = "5H23098";

$newString = $string[0].substr($string, 2);

Result: 523098

Takes the first character + all characters after position 2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top