How to get the second characters from the end of a string in PHP

3 Answers

0 votes
$ch = substr("php programming", -2, 1);

echo $ch;



/*
run:

n

*/

 



answered Mar 5, 2021 by avibootz
0 votes
$s = "php programming";

$ch = substr($s, strlen($s) - 2, 1);

echo $ch;




/*
run:

n

*/

 



answered Mar 5, 2021 by avibootz
0 votes
$s = "php programming";

$ch = $s[strlen($s) - 2];

echo $ch;




/*
run:

n

*/

 



answered Mar 5, 2021 by avibootz

Related questions

...