PHP strrchr — Find the last occurrence of a character in a string
<?php
// get last directory in $PATH
$dir = substr(strrchr($PATH, ":"), 1);
// get everything after last newline
$text = "Line 1
Line 2
Line 3";
$last = substr(strrchr($text, 10), 1 );
?>
phpCopy<?php
$string = "This is a string";
$lastCharPosition = strlen($string) - 1;
for ($x = $lastCharPosition; $x < strlen($string); $x++) {
$newString = $string[$x];
}
echo "The last char of the string is $newString.";
?>
phpCopy<?php
$string = "This is a string";
$lengthOfString = strlen($string);
$lastCharPosition = $lengthOfString-1;
$lastChar = $string[$lastCharPosition];
echo "The last char of the string is $lastChar.";
?>