-5

Consider the following string:

Hello World

My aim is to remove all the characters prior to the last character ("d"), excluding the last character.

What is the most efficient way to accomplish this in PHP?

Ben Löffel
  • 931
  • 4
  • 12
  • 29

2 Answers2

6

Use substr() in php

<?php 
$str = "Hello World";
echo substr($str, -1);
?>
Aman Kumar
  • 4,533
  • 3
  • 18
  • 40
1

Just get the last

 substr("Hello World", -1); // returns "d"
Atural
  • 5,389
  • 5
  • 18
  • 35
Ali Raza
  • 842
  • 7
  • 13