简体   繁体   English

动态更改超链接参数值

[英]Change hyperlink parameter value dynamically

Please advise on how to do this. 请告知如何执行此操作。

I have a html page with two different links like below 我有一个带有两个不同链接的html页面,如下所示

1)  http://domainONE.com/?a=100&b=$bvalue (this url is around in 45 places)
2)  http://domainTWO.com/?a=200&b=$bvalue (this url is around in 30 places)

Now I would like dynamically change (prefer PHP based solution) to assign b= value(like link1, link2 link3…link45) for domainONE.com and then b= number (like link46, link47 link48…link75). 现在,我想动态更改(首选基于PHP的解决方案),为domainONE.com分配b =值(如link1,link2 link3…link45),然后为b =数字(如link46,link47 link48…link75)。 Looking to assign the b=$bvalue using a loop or other ways based on domain name so I don't have to hardcode by finding each url on the page with link1 till link75) 希望使用循环或其他基于域名的方式为b = $ bvalue赋值,因此我不必通过在页面上使用link1直到link75找到每个URL来进行硬编码)

I can explain more if it's not clear. 如果不清楚,我可以解释更多。 I am trying not to use jquery based solution thinking if that takes time to manipulate. 我试图不使用基于jquery的解决方案思维,如果这需要时间来操纵。

Regards 问候

Something like this with a switch: 像这样的开关:

switch($_SERVER['SERVER_NAME']) {
    case 'www.domain1.com':
        $bvalue = 100;
        break;

    case 'www.domain2.com':
        $bvalue = 200;
        break;
}

Or something with an array: 或带有数组的东西:

$domains = array('www.domain1.com' => array('bvalue' => 100),
                 'www.domain2.com' => array('bvalue' => 200),
);

$current = $_SERVER['SERVER_NAME'];

$bvalue = $domains[$current]['bvalue'];

Depending on your requirements you might look through $_SERVER specifically $_SERVER['HTTP_HOST'] for something else or you may need to manipulate it somewhat to get the string that you want. 根据您的要求,您可能会通过$_SERVER特别是$_SERVER['HTTP_HOST']查看其他内容,或者您​​可能需要对其进行某种程度的操纵才能获得所需的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM