Call div when specific link

Asked

Viewed 53 times

0

I have a file with dynamic content in PHP. I have a div that I want to be shown whenever the site link is /who-we.

How to do this in PHP?

  • Something like if ($url == '/quem-somos') { show_div(); }. For more details, add the relevant code to the question.

2 answers

1

Can use preg_match to check if the URL ends with the string /quem-somos or /quem-somos/:

<?php
$url_atual = $_SERVER[REQUEST_URI]; // URL da página atual
$match = preg_match('\/quem-somos[\/]?$/', $url_atual, $matches); // verifica a string na URL
if($matches){ // se casou, carrega a div
?>
<div></div>
<?php
} // fecha o if
?>

Regex test in Regexr

0

From what I understand and only you use the GET mode.

$url=$_GET['mostrar'];
if($url="quem-somos"){
   echo "<div id='IDdaDiv'> </div>";   
}

So if the url is site.com/index.php? show=who-we are He will show the div case n goes. you can use URL friendliness to n display "index.php? show=" and yes only "site.com/who-we are"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.