Answers for "php find last occurrence of character in string"

PHP
13

get last character of string php

substr("testers", -1); // returns "s"
Posted by: Guest on March-05-2020
1

get last word from string php

function getLastWord($string)
    {
        $string = explode(' ', $string);
        $last_word = array_pop($string);
        return $last_word;
    }
Posted by: Guest on February-26-2021
0

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\nLine 2\nLine 3";
$last = substr(strrchr($text, 10), 1 );
?>
Posted by: Guest on May-15-2022
0

PHP strrpos — Find the position of the last occurrence of a substring in a string

<?php

$pos = strrpos($mystring, "b");
if ($pos === false) { // note: three equal signs
    // not found...
}

?>
Posted by: Guest on May-15-2022

Code answers related to "php find last occurrence of character in string"

Browse Popular Code Answers by Language