Help with referencing url in code

I am trying to display something on web pages that show this in the url: "sub" for example: ...com/videos/category/1/sub536. It was suggested I try this code:

$page = basename($_SERVER['PHP_SELF']); 
if ($page=="....") {
echo Hello World; 
} elseif ($page=="....php") {
Some Other code... 
}

but I don't know where to place the url in that code to make it purposeful.
Also, I'm not sure that I need if/else, just would like if: /videos/category/1/sub__ then show echo

Well, when I put that code on the page, as-is, I see "page isn't working.

Any guidance/suggestion is appreciated