Jump to content

Unexpected T_CONSTANT_ENCAPSED_STRING


Techairlines

Recommended Posts

Hello. I'm relatively new to PHP and can't figure out what's wrong.

 

 

       function tweet_button () {        echo '<div class="twitter-share vcount"> <a class="twitter-button" rel="external nofollow" title="Share this article on Twitter" href="http://twitter.com/share?text=<?php echo $shareTitle; ?>+-&url=<?php echo $shareUrl; ?>&via=<?php if (!$retweetNick == '') { echo $retweetNick; } ?>&related=<?php if (!$retweetrelate == ''){ echo $retweetrelate; } ?>:<?php if (!$retweetrelate == '') { echo $retweetrelatedesc; } ?>" target="_blank">Tweet this article</a> <span class="twitter-count"><?php echo $retweetInfo; ?></span></div>';    }

 

 

This was part of the code of a WordPress plugin I'm trying to make and when I try to activate the plugin, it gives me

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\xampp\htdocs\wordpress\wp-content\plugins\sample-plugin\sample-plugin.php on line 51

 

Line 51 is the line that starts with &related=

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/214967-unexpected-t_constant_encapsed_string/
Share on other sites

You are echoing a long string which is delimited by single quotes, but in the middle of the string you have more single quotes -- which is illegal unless you quote them, plus you have PHP tags inside the string (I'm not sure that you want that).

 

To fix, replace the strings like

(!$retweetNick == '')

 

with

(!$retweetNick == "")

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.