I'm actually trying to find a way to get the href in my website url because i want to change the typo color regarding this href, but i can't find how to do it.
For example, if i have the URL
http://localhost/website/?date=2019#Presse
I would like to get the "Presse"
Here is my code :
<div class=" col-sm-3 col-12">
<div class = "row">
<div class="col-12"><a class = "<?php //php code to get the href ?>" href="#Distinctions">Distinctions</a></div>
<div class="col-12"> <a class = "<?php //php code to get the href ?>" href="#Presse">Presse</a></div>
<div class="col-12"> <a class = "<?php //php code to get the href ?>" href="#Expositions">Expositions</a></div>
<div class="col-12"><a class = "<?php //php code to get the href ?>" href="#Conférences">Conférences</a><br/><br/></div>
Is it possible to get this in PHP ?
Thanks
答案 0 :(得分:0)
尝试一下,希望对您有帮助
echo $str=explode("#","http://localhost/website/?date=2019#Presse")[1];
//output Presse
答案 1 :(得分:0)
您可以使用此
<?php
$url = "Thttp://localhost/website/?date=2019#Presse";
$presse = parse_url($url,PHP_URL_FRAGMENT);
echo $presse;
?>
我用过parse_url
。该函数解析URL,并返回一个包含该URL各种组件中任何一个的关联数组。数组元素的值未经过URL解码。
PHP_URL_FRAGMENT 仅检索特定的URL组件。有关更多信息,您可以访问manual
这是现场demo
答案 2 :(得分:0)
您应该获得url参数 然后爆炸以分割日期和字符串,然后将您的字符串用作类 试试这个代码
class="<?php if (isset($_GET['date'])) { $string=explode('#',$_GET['date']); echo $string[1]; } else { echo 'red'; }" ?>
答案 3 :(得分:0)
<a href="<?php //php code to get the href ?>#Distinctions" class="classname">Title</a>
答案 4 :(得分:0)
感谢您的所有回答。 抱歉,但我想我的问题还不清楚:我必须先获取完整的URL,因为#id可以更改。例如,它可以以#Presse或#Distinctions结尾(或者我只是不理解您的答案,也可以:))
但是我不知道为什么,我有一个“照明”,并且我在JS中做到了(它正在工作):
function changeBold(name)
{
document.getElementById(name).className = "navigationB";
if(name != 'Distinctions') document.getElementById('Distinctions').className = "navigation";
if(name != 'Presse') document.getElementById('Presse').className = "navigation";
if(name != 'Expositions') document.getElementById('Expositions').className = "navigation";
if(name != 'Conférences') document.getElementById('Conférences').className = "navigation";
}