0

I have event listings that look like this

PAPA ROACH AT THE PARAMOUNT IN HUNTINGTON ON APR 28, 2015

Im trying to remove everything after the last "ON"

$s="PAPA ROACH AT THE PARAMOUNT IN HUNTINGTON ON APR 28, 2015";
echo strstr($s, 'ON', true);

I came up with something like this but it removes everything after the first "ON" it detects, is there a way to run this backwards or tell to skip to the last "ON"

Tcmxc
  • 481
  • 1
  • 7
  • 23

1 Answers1

1

You can use strrpos function to perform search from the end of the string:

$s="PAPA ROACH ON THE PARAMOUNT IN HUNTINGTON ON APR 28, 2015";
echo substr($s, 0, strrpos($s, ' ON ') + 3); // +3 is to include the word ON
astax
  • 1,769
  • 1
  • 14
  • 23
  • I think in order to get the word ON you need to search for ' ON ' including withe spaces, otherwise it will stop by the first occurrence. – bpinhosilva Apr 28 '15 at 23:21