我在我的网站的每个页面上都使用了这个,如下所示,以避免在Firefox中查看网站时显示社交按钮:
<?php
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
include("/includes/social_buttons.php");?>
我的
social_buttons.php
包含以下代码:
<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->
<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->
<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->
现在的问题是,我想在social_buttons.php中添加一些额外的内容,这些内容将在每个浏览器中显示,包括firefox。
所以我的尝试(哪些不起作用!)要将它全部放在我的social_buttons.php中,然后用更简单的包含调用来调用它
<?php include("/includes/social_buttons.php");?>
所以social_buttons.php的内容看起来像这样:
<?php if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
echo ("
<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->
<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->
<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->
");?>
SOME OTHER CODE I WANT TO INCLUDE
有没有办法做到这一点?
答案 0 :(得分:0)
heredoc怎么办?
if ($isFirefox)
{
echo ' ';
}
else
{
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo <<<BLAH
Hello World! I'm $name. <a href="$url">This is a link to this site</a>
BLAH; // important: this keyword has to be at the beginning of a line (do not add any char before this keyword)
}
或者转义你的javascript(双引号)