1

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.net/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";    
?>
1
  • 3
    You really have to be more specific than "it won't let me". That's not a very programmer-friendly term. Commented Mar 12, 2011 at 19:58

3 Answers 3

3

Is this the complete code? Better is not to echo it at all:

<td>
    <script src="http://connect.facebook.net/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.

Sign up to request clarification or add additional context in comments.

2 Comments

and even <?=$row['item_content']?>
@CappY: Also possible, but that won't work with short open tags disabled, which they are by default.
3

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.net/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.net/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

Comments

0

Try this, you must escape some symbols

<?php
       echo '    <td>\'<script src="http://connect.facebook.net/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";

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.