php 解析错误:语法错误,意外的 T_STRING,需要 ',' 或 ';'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17696815/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:16:52  来源:igfitidea点击:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

phpwordpressparse-errorphp-parse-error

提问by Jogodosshu

I am trying to use following codes to have an email share button in a WordPress website. But adding this codes in single.php shows "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in .......... in line 72". Please help me someone to fix this issue.

我正在尝试使用以下代码在 WordPress 网站中设置电子邮件共享按钮。但是在 single.php 中添加此代码会显示“解析错误:语法错误,意外的 T_STRING,期望 ',' 或 ';' 在…………在第 72 行”。请帮我解决这个问题。

<?php echo "<a href="mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20<?php bloginfo('name'); ?>&body=<?php the_title('','',true); ?>%20%20%3A%20%20<?php echo get_the_excerpt(); ?>%20%20%2D%20%20%28%20<?php the_permalink(); ?>%20%29" title="Email to a friend/colleague" target="_blank">Share via Email</a>"; ?>

回答by DarkMantis

You need to escape your quotes or change the inner double-quotes to single quotes

您需要转义引号或将内部双引号更改为单引号

[edit]

[编辑]

Something like this:

像这样的东西:

<?php 
echo '<a href="mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20'. bloginfo('name') .'&body='.the_title('','',true).'%20%20%3A%20%20'. get_the_excerpt() .'%20%20%2D%20%20%28%20'. the_permalink() .'%20%29" title="Email to a friend/colleague" target="_blank">Share via Email</a>'; 
?>

回答by DarkMantis

Escape your quotes:

转义你的报价:

<?php echo "<a href=\"mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20<?php bloginfo('name'); ?>&body=<?php the_title('','',true); ?>%20%20%3A%20%20<?php echo get_the_excerpt(); ?>%20%20%2D%20%20%28%20<?php the_permalink(); ?>%20%29\" title=\"Email to a friend/colleague\" target="_blank\">Share via Email</a>"; ?>

Tip:Use a good text editor that supports syntax highlighting. That'll save you a lot of time.

提示:使用支持语法高亮的优秀文本编辑器。那会为你节省很多时间。

回答by Bindiya Patoliya

Try

尝试

<?php echo "<a href='mailto:type%20email%20address%20here?subject=I%20wanted%20to%20share%20this%20post%20with%20you%20from%20<?php bloginfo('name'); ?>&body=<?php the_title('','',true); ?>%20%20%3A%20%20<?php echo get_the_excerpt(); ?>%20%20%2D%20%20%28%20<?php the_permalink(); ?>%20%29' title='Email to a friend/colleague' target='_blank'>Share via Email</a>"; ?>