echo in php code is causing problems
The echo
in the last line seems to be causing problems. However I can't take it out or it'll just print the line directly. How can I rewrite that part? Also, is there anything else wrong with the way the other php functions are written?
$output .= "
<script src='http://platform.twitter.com/widgets.js'></script>
<a href='http://twitter.com/share' class='twitter-share-button'
data-url='". the_permalink() ."'
data-via='username'
data-text='". the_title() ."'
data-count='horizontal'>Tweet
</a>
<iframe src='http://www.facebook.com/plugins/like.php?href=". echo urlencode(get_permalink($post->ID)) ."&layout=button_count&show_faces=false&width=90&action=like&colorscheme=light' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidde开发者_如何学Cn; width:90px; height:20px;'></iframe>'";
You should remove the "echo", you don't need it in a string concatenation:
$output .= "
<script src='http://platform.twitter.com/widgets.js'></script>
<a href='http://twitter.com/share' class='twitter-share-button'
data-url='". the_permalink() ."'
data-via='username'
data-text='". the_title() ."'
data-count='horizontal'>Tweet
</a>
<iframe src='http://www.facebook.com/plugins/like.php?href=". urlencode(get_permalink($post->ID)) ."&layout=button_count&show_faces=false&width=90&action=like&colorscheme=light' scrolling='no' frameborder='0' allowTransparency='true' style='border:none; overflow:hidden; width:90px; height:20px;'></iframe>'";
echo
does not belong in the middle of a string. It doesn't return anything so it doesn't make sense to have it in the middle of a concatenation.
The concatenation you are doing is very long and I believe has a few mistakes.
There is an extra single quote at the end.
The url you are constructing for the iframe has you both doing a urlencode but also has you manually escaping ampersands.
A much better way of constructing a url is with: http_build_query
and let the system put it together for you. Link: http://www.php.net/manual/en/function.http-build-query.php It is almost always better to let the system put the url together for you. Since it is in the middle of a bunch of html, you can then run htmlentities
on the whole thing: http://www.php.net/manual/en/function.htmlentities.php That will make it appropriate to use inside of html.
There is no way of determining if the other functions are incorrect unless you put up the code for them. If they always return strings, you're fine.
Don't be afraid of breaking up your code into multiple chunks if it's getting complicated.
It looks like you have an additional ' (apostrophe) at the end of your output.
</iframe>'
精彩评论