How can I check the URL path for certain folders? I ask so that if we’re in a certain folder, we can make a tab selected in the nav bar (just apply a style to that specific li).
So far I know
$pagePath = $_SERVER['REQUEST_URI'];
So I can get a return that says something like /music/song/120/ (or whatever it is). What kind of php function can I use that says
if $pagePath has “music”, then do this. Meaning, if the path is /music/ or /music/song, I should be able to
I plan on using this multiple times,
if $pagePath has downloads do this
if $pathPath has band do this
and so on.
Any suggestions?
You could
explode()the path on/and then usein_array()to check for existence.However, this could yield problems with paths like
/bands/something/musicwhere the state would depend on whether you check forbandsbeforemusicor vice versa. In that case you couldexplode()with$limit = 2(to get only two parts, i.e., split on first/only) and compare your predefined path segments to the first part of the exploded path.E.g.