Get the last word in the URL and delete what is not needed


Great guys have helped me a lot in this other post:

Get last word from URL after a slash in PHP

Now I am facing another issue.

How can I say something like this in PHP:

if in $last_word you find also -0.htm then delete -0.htm

I explain my $last_word now shows test-0.htm

But I do not need -0.htm

I only need "test".

How do I say in PHP to delete -0.html and to grab only "test".

Thanks for your help. Since it is a dynamic script I obviously do not know what is before "-0.html". The word "test" is only an example. Just to let you know that "test" is represented by a variable in my code, and it works. Now I only need to tell to the code to eliminate 0.html when is found.


$last_word = str_replace(array('-0.html','-0.htm'), '', $last_word);

Hope this helps. It will replace the string (-0.html or -0.htm) even if found somewhere else than at the end of $last_word.