Get last word in URL and delete what is not necessary
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开发者_StackOverflow中文版 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.
THANK YOU
$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.
Trying to remove -0.htm
at the end of $last_word
:
Regex is an easy way to go:
$last_word = preg_replace('/\-0\.htm$/', '', $last_word);
The $
means 'the end', which means the -0.htm
has be be at the end.
If instead of -0.htm
you want to remove -0.html
:
$last_word = preg_replace('/\-0\.html$/', '', $last_word);
精彩评论