我需要在此链接上插入实际网址:
<a href="http://www.facebook.com/sharer.php?u=**MY_URL**&t=<?php echo($title); ?>" target="blank">Share on Facebook</a>
哪种方法最好?谢谢!
答案 0 :(得分:2)
您可以使用超全局$_SERVER
数组; - )
<?php
$myURL = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>
您的链接将是......
<a href="http://www.facebook.com/sharer.php?u=<?php echo($myURL); ?>&t=<?php echo($title); ?>" target="blank">Share on Facebook</a>
// 编辑:
$myURL
应为urlencode()
d并检查协议 - &gt;
<?php
$protocol = 'http://';
if(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' || $_SERVER['SERVER_PORT'] == 443) {
$protocol = 'https://';
}
$myURL = urlencode($protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
?>