[英]PHP - links and modification of links
Well, I'm editing WP theme and creating network so I need to get url and modificate it for use in <a></a>
tags. 好吧,我正在编辑WP主题并创建网络,因此我需要获取url并对其进行修改以用于
<a></a>
标签。 I created function called urlbg(); 我创建了一个名为urlbg()的函数; and on normal domain (like www.xyz.com) it works but in subdomain it don't work.
并在普通域(如www.xyz.com)上有效,但在子域中则无效。 I called functions in
<a></a>
tags like so: 我在
<a></a>
标记中调用了函数,如下所示:
<a href="'. urlbg( 'ark') . '" title="ARK: Survival Evolved"><img src="'. content_url() .'/themes/newsgamer/images/ark.png"></a>
Problem is, in normal domain (like www.xyz.com) when i use functions eg. 问题是,在正常领域(例如www.xyz.com)中,当我使用例如 urlbg( 'ASD' );
urlbg('ASD'); i get ASD.xyz.com and thats what i want, BUT in other way when i use the same code in subdomain (like foo.xyz.com) and when i called function in urlbg( 'ASD' );
我得到了ASD.xyz.com ,这就是我想要的,但是当我在子域中使用相同的代码(如foo.xyz.com)并且当我在urlbg('ASD')中调用函数时,会以其他方式获得;
<a></a>
tags, i get foo.xyz.com/ASD. <a></a>
标签,我得到foo.xyz.com/ASD。 (but need ASD.xyz.com ). (但需要ASD.xyz.com )。 Sorry for my bad English I hope you'll understand me and know whats my problem.
对不起,我的英语不好,希望您能理解我,知道我的问题所在。
Code of function urlbg(); 功能代码urlbg();
function urlbg($prefix){
$siteUrl = get_site_url();
$url = str_replace("http://", "https://", "". $prefix . ".", $siteUrl);
return $url;
}
This should do the trick: 这应该可以解决问题:
function urlbg($prefix){
$siteUrl = get_site_url();
$url = 'https://'.$prefix.strstr($siteUrl, '.');
return $url;
}
Assuming you will always have this pattern http(s)://something_to_replace.something_to_keep. 假设您将始终使用此模式http(s)://something_to_replace.something_to_keep。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.