为什么我收到解析错误:语法错误,第46行出现意外的''T_ENCAPSED

时间:2019-07-14 21:38:00

标签: php variable-assignment

我试图将一些嵌入了PHP的html代码分配给一个PHP变量,但是当我运行该代码时,出现Parse错误:语法错误,意外的''(T_ENCAPSED_AND_WHITESPACE),期望标识符(T_STRING)或变量(T_VARIABLE )或第46行上的/var/www/html/like/index.php中的数字(T_NUM_STRING),我们将不胜感激!

我已经尝试确保对引号进行检查,例如,如果变量的智能化以双引号开头,那么我要确保其中的所有代码都具有单引号而没有双引号。

我不正确吗?

这是我的代码...

 $variable = "
  <div class='posts-wrapper'>
   <?php foreach ($posts as $post): ?>
    <div class='post'>
      <div class='post-info'>
        <!-- if user likes post, style button differently -->
        <i <?php if (userLiked($post['id'])): ?>
              class='fa fa-thumbs-up like-btn'
          <?php else: ?>
              class='fa fa-thumbs-o-up like-btn'
          <?php endif ?>
          data-id='<?php echo $post['id'] ?>'><img src='image.ico'></i>
        <span class='likes'><?php echo getLikes($post['id']); ?></span>
        &nbsp;&nbsp;&nbsp;&nbsp;

        <i <?php if (userStared($post['id'])): ?>
            class='fa fa-star star-btn'
          <?php else: ?>
            class='fa fa-star-o star-btn'
          <?php endif ?>
          data-id='<?php echo $post['id'] '><img src='image.ico'></i>
        <span class='stars'><?php echo getStars($post['id']); ?></span>
        &nbsp;&nbsp;&nbsp;&nbsp;

        <i <?php if (userBiked($post['id'])): ?>
            class='fa fa-heart heart-btn'
          <?php else: ?>
            class='fa fa-heart-o heart-btn'
          <?php endif ?>
          data-id='<?php echo $post['id'] ?>'><img src='image.ico'></i>
        <span class='bikes'><?php echo getBikes($post['id']); ?></span>
        &nbsp;&nbsp;&nbsp;&nbsp;

        <i
          <?php if (userDisliked($post['id'])): ?>
              class='fa fa-thumbs-down dislike-btn'
          <?php else: ?>
              class='fa fa-thumbs-o-down dislike-btn'
          <?php endif ?>
          data-id='<?php echo $post['id'] ?>'><img src='image.ico'></i>
        <span class='dislikes'><?php echo getDislikes($post['id']); ?></span>
        &nbsp;&nbsp;&nbsp;&nbsp;
      </div>
   </div>
   <?php endforeach ?>
  </div>
";

echo $variable;

?>

0 个答案:

没有答案