[英]Share link to facebook with PHP and Javascript
I'm new to PHP and I've this code I'am not sure why it redirect me to http://www.facebook....php?s=100&p[url]=
instead I want http://www.facebook....php?s=100&p[url]=test
. 我是PHP的新手,我不确定这段代码为什么会将我重定向到
http://www.facebook....php?s=100&p[url]=
而不是我想要的http://www.facebook....php?s=100&p[url]=test
。
<?php
$url = 'test' ;
echo "
<a target='_blank' href='http://www.facebook.com/sharer/sharer.php?s=100&p[url]=' " . $url . " '&p[images][0]=https://scontent-vie1-1.xx.fbcdn.net/hphotos-xta1/v/t1.0-9/11102691_483697748448554_6954591283482418788_n.png?oh=78cfe0fb891a30cf56d78df08e65e70f&oe=55F12850;p[title]=Desgin Football online and win&p[summary]=Vote and Win '>
<img style='width: 50px;
height: 50px; margin-left: 35px;
margin-right: auto;' src='2.png'></a>
" ;
?>
Any ideas? 有任何想法吗?
Don´t copy old code, the sharer.php only takes the URL as parameter since many years: 不要复制旧代码,多年来,sharer.php仅将URL作为参数:
http://www.facebook.com/sharer/sharer.php?u=<your-urlencoded-url>
For example: 例如:
echo '<a href="http://www.facebook.com/sharer/sharer.php?u=' . urlencode($url) . '">test</a>';
your code needs to be updated as @luschn said 您的代码需要按@luschn所述进行更新
<a target="_blank" href="http://www.facebook.com/sharer.php?u=<?=rawurlencode("http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);?>">
<img src="images/facebook.png" alt="facebook"/>
</a>
the u parameter needs urlencoded value (enter your own URL, if not current page is shared) u参数需要urlencoded值(如果未共享当前页面,则输入您自己的URL)
for differences between rawurlencode and urlencode please read this thread urlencode vs rawurlencode? 对于rawurlencode和urlencode之间的差异,请阅读此线程urlencode与rawurlencode吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.