开发者

PHP line of code [duplicate]

开发者 https://www.devze.com 2023-04-12 04:55 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to get URL of current page in PHP
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to get URL of current page in PHP

ive been searching all over and i do not know php too well but all im trying to to do is display:none in php when on a certain page (/site/page/).

basically <?php if on this 开发者_JS百科page -->(/page/site/)><?php //echo $this->?><div or span id="dropdown_navigation" style="display:none"></div> <?php endif; ?>

i know that code is all funky but i just wanted to kinda explain what im trying to do in that made up code with no php knowledge. the div id im trying to hide when on a certain page is a drop down menu called "dropdown_navigation"

any help would be greatly appreciated.

thanks.


Alright. You can go like so:

<?php if($_SERVER['REQUEST_URI']=='/the/page.html'){
echo '<div id="dropdown_navigation"...';
} ?>

That should do it. Replace ... with whatever you need. If you need to use a single quote in there, you'll have to escape it by prepending a backslash (i.e. \')

This only works with the relative URL.


There are two global arrays which contain the information about the url:

  1. $_SERVER['REQUEST_URI'] :

  2. $_SERVER['QUERY_STRING'] : This will contain the query string something after the ? in the url.

The PHP script would be then :

<?php
if($_SERVER['REQUEST_URI'] == 'your specific page url') {
 ?>   
<div or span id="dropdown_navigation" style="display:none"></div>

<?php }  ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消