Conditional PHP, if last segment of url = 'contact'
Is it possible to write conditional PHP that checks the last segment (or any segemnt) of the url?
The following can check if the first url segment
<?php if (arg(0) == 'contact'): ?>
stuff to do here
<?php endif; ?>
My issue is that I need to check for the last url segment, the problem being that the site is in the web r开发者_开发问答oot when live but in my localhost folder when being worked on locally. So I cant just go for the 2nd segment if my site will be mysite.com/contact when live, as when its locally it will be localhost/mysite/contact
Thanks
Why not use parse_url ?
There are numerous ways to achieve this but you probably want to stick to drupal-specific functions where possible. That way, if the underlying implementation changes, your code can still work. The drupal function arg()
called without any parameters will return all components from the path, so you can just:
$args = arg();
<?php if ( $args[count($args)-1] ) == 'foo' ): ?>
精彩评论