DekGenius.com
PHP
get last character of string php
substr("testers", -1); // returns "s"
get last characters of string in php
<?php
echo substr('Telangana', -3); // ana
print "<br/>";
echo substr('Telangana', -1, 1); // a
print "<br/>";
echo substr('Telangana', 0, -1); // Telangan
?>
get last word from string php
function getLastWord($string)
{
$string = explode(' ', $string);
$last_word = array_pop($string);
return $last_word;
}
get last letter in php
substr("testers", -1); // returns "s"
//Or, for multibyte strings :
mb_substr("multibyte string…", -1); // returns "…"
Get the Last Character of a String in PHP
phpCopy<?php
$string = 'This is a string';
$lastChar = substr($string, -1);
echo "The last char of the string is $lastChar.";
?>
php extract last n words of string
<?php
$str = "NAME WITH SPACES FIELD1 FIELD2 FIELD3 FIELD4";
preg_match("/(S+)s(S+)s(S+)s(S+)$/", $str, $matches);
var_dump($matches);
/* array(5) {
[0] => string(27) "FIELD1 FIELD2 FIELD3 FIELD4"
[1] => string(6) "FIELD1"
[2] => string(6) "FIELD2"
[3] => string(6) "FIELD3"
[4] => string(6) "FIELD4"
} */
Get the Last Character of a String in PHP
phpCopy<?php
$string = "This is a string";
$lastChar = $string[-1];
echo "The last char of the string is $lastChar.";
?>
get last word of string php
$split = explode(" ", $string);
echo $split[count($split)-1];
Get the Last Character of a String in PHP
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.";
?>
Get the Last Character of a String in PHP
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.";
?>
get last word of string php
$split = explode(" ", $string);
echo $split[count($split)-1];
Get the Last Character of a String in PHP
phpCopysubstr($stringName, $startingPosition, $lengthOfSubstring);
© 2022 Copyright:
DekGenius.com