What is wrong with this PHP code - Unexpected T_CONSTANT
I keep getting the following error in my log
PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'
The error is related to this line but I'm not sure what's wrong with it
<?php
if ($num != null) {
$query_string = 'msisdn=' . $num . '&ref=' . get_post_meta($post->ID, "ref", $single = tr开发者_开发问答ue) ;
echo '<div class="highlight"><a href="http://www.site.com/exJoin?signup=y&' . htmlentities($query_string) . '"><b>Join Now</b></a></div>';
}
else{
echo '<div class="highlight"><a href="<?php echo TeraWurflHelper::getPhoneHref('+2711111111'); ?>"><b>Join Now</b></a></div>';
}
?>
Your adding PHP opening tags when you are already within a PHP tag. You should change to:
<?php
if ($num != null) {
$query_string = 'msisdn='.$num.'&ref='.get_post_meta($post->ID, "ref", $single = true);
echo '<div class="highlight"><a href="http://www.site.com/exJoin?signup=y&'.htmlentities($query_string).'"><b>Join Now</b></a></div>';
} else {
echo '<div class="highlight"><a href="' . TeraWurflHelper::getPhoneHref('+2711111111') . '"><b>Join Now</b></a></div>';
}
?>
else{echo '<div class="highlight"><a href="<?php echo TeraWurflHelper::getPhoneHref('+2711111111'); ?>"><b>Join Now</b></a></div>';}
There lays the problem. You see the '+2711111111'
. it uses " ' ". You'll have to escape that one, because it will end your string there.
Also, you do not need the opening tags for php in their... just remove them as you are already in a php-snippet.
Try this:
<?php
if ($num != null) {
$query_string = 'msisdn=' . $num . '&ref=' . get_post_meta($post->ID, "ref", $single = true);
echo '<div class="highlight"><a href="http://www.site.com/exJoin?signup=y&'.htmlentities($query_string).'"><b>Join Now</b></a></div>';
} else {
echo '<div class="highlight"><a href="'.TeraWurflHelper::getPhoneHref('+2711111111').'"><b>Join Now</b></a></div>';
}
?>
Your problem was that you had a <?php echo... ?>
in the middle of a string that was already being echo
ed. This had a '
in it, which was the type of quote used to encapsulate the string that was already being echo
ed. You could escape it (like \'
) but this would have your resulted in <?php echo... ?>
being echo
ed into your HTML, which I doubt is what you want, instead your should remove this and put the function call into the middle of your echo.
This should be easy spot if you are using an editor/IDE with syntax highlighting. If your are not, look at EditPad, Notepad++ (editors) or Eclipse (IDE). Or Google it...
You are trying to echo a string containing <?php ?>
tags
echo '<div class="highlight"><a href="<?php echo TeraWurflHelper::getPhoneHref('+2711111111'); ?>"><b>Join Now</b></a></div>';
Should propably be
echo '<div class="highlight"><a href="'.TeraWurflHelper::getPhoneHref('+2711111111').'"><b>Join Now</b></a></div>';
精彩评论