Home / PHP Tips Generated By ChatGPT / Getting the Last Character of a String in PHP Access the last character of a string by using negative indexing with substr(). Source Code $str = "Hello"; echo substr($str, -1); // Outputs: "o"