admin管理员组文章数量:1418103
I want to echo out a simple Facebook like button script in PHP, but it wont let me. Here's what the script would look like:
<?php
echo " <td>'<script src=".js#xfbml=1"></script><fb:like href="http://#" layout="button_count" show_faces="false" width="450" font=""></fb:like>'</td>\n" ;
echo " <td>".$row['item_content']."</td>\n";
?>
I want to echo out a simple Facebook like button script in PHP, but it wont let me. Here's what the script would look like:
<?php
echo " <td>'<script src="http://connect.facebook/en_US/all.js#xfbml=1"></script><fb:like href="http://#" layout="button_count" show_faces="false" width="450" font=""></fb:like>'</td>\n" ;
echo " <td>".$row['item_content']."</td>\n";
?>
Share
Improve this question
edited Jun 29, 2011 at 20:56
OMG Ponies
333k85 gold badges535 silver badges508 bronze badges
asked Mar 12, 2011 at 19:56
user653480user653480
651 gold badge3 silver badges7 bronze badges
1
- 3 You really have to be more specific than "it won't let me". That's not a very programmer-friendly term. – Jon Commented Mar 12, 2011 at 19:58
3 Answers
Reset to default 3Is this the plete code? Better is not to echo
it at all:
<td>
<script src="http://connect.facebook/en_US/all.js#xfbml=1"></script>
<fb:like href="http://#" layout="button_count" show_faces="false" width="450" font=""></fb:like>
</td>
<td><?php echo $row['item_content']; ?></td>
Embed PHP in HTML, not vice versa.
You have to properly escape your quotation marks.
Everytime you are using a double-quote ("
) in a double-quoted string, you must prepend it with a backslash (\
) as such:
echo " <td>'<script src=\"http://connect.facebook/en_US/all.js#xfbml=1\"></script><fb:like href=\"http://#\" layout=\"button_count\" show_faces=\"false\" width=\"450\" font=\"\"></fb:like>'</td>\n";
echo " <td>".$row['item_content']."</td>\n";
Alternatively, you could single-quote ('
) the whole string, but note that in single-quoted strings, the only escape sequences recognized are \'
and \\
. In-line variables are also not recognized.
echo ' <td>\'<script src="http://connect.facebook/en_US/all.js#xfbml=1"></script><fb:like href="http://#" layout="button_count" show_faces="false" width="450" font=""></fb:like>\'</td>' ;
echo "\n <td>".$row['item_content']."</td>\n";
For more information, please read the PHP Documentation page on Strings:
PHP Documentation: Strings
Try this, you must escape some symbols
<?php
echo ' <td>\'<script src="http://connect.facebook/en_US/all.js#xfbml=1"></script><fb:like href="http://#" layout="button_count" show_faces="false" width="450" font=""></fb:like>\'</td>\n';
echo " <td>".$row['item_content']."</td>\n";
?>
本文标签: How to use javascript inside a PHP echo functionStack Overflow
版权声明:本文标题:How to use javascript inside a PHP echo function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745271618a2650926.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论