【问题标题】:PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in C:\apache2triad\htdocs\imagedisplay.php on line 28 [closed]PHP 解析错误:语法错误,意外的 T_CONSTANT_ENCAPSED_STRING,期待 ',' 或 ';'在第 28 行的 C:\apache2triad\htdocs\imagedisplay.php [关闭]
【发布时间】:2012-05-27 07:07:05
【问题描述】:

我在执行代码时遇到错误:

PHP 解析错误:语法错误,意外的 T_CONSTANT_ENCAPSED_STRING,需要 ',' 或 ';'在 C:\apache2triad\htdocs\imagedisplay.php 第 28 行

<?php

$dir= "C:\apache2triad\htdocs\phppgadmin\images\phpimages";

$file_display= array('jpg', 'jpeg', 'png', 'gif');

if(file_exists($dir)== false) 
{
  echo "directory x not found";
}
else
{
  $dir_content= scandir($dir);

  foreach($dir_content as $file)
  {
    $file_type = strtolower(end(explode('.', $file)));
     
    // echo "$file <br> ";

    if($file !=='.' && $file !=='..')
    {
      //echo "$file <br> ";   
      echo "<img src="', $dir, '/', $file, '" alt="', $file, '"/>";
    }      
  }   
}
?>

【问题讨论】:

  • 第 28 行在哪里?还有一个点(.)用于连接 PHP 中的字符串,而不是逗号...
  • @lix: echo 接受多个逗号分隔的参数
  • 请在下次正确缩进和格式化您的代码。
  • @marc - 知道吗!好信息 - 谢谢!
  • 像往常一样,带有语法高亮的编辑器或 IDE 会有所帮助。

标签: php


【解决方案1】:
echo "<img src="', $dir, '/', $file, '" alt="', $file, '"/>";
               ^^-- here

你在这里实际上有两个不同的字符串背靠背,使这条线完全无效。

【讨论】:

  • 那么如何让它发挥作用
  • 从学习基本的 PHP 语法规则开始。我们可以告诉你解决方案,但你什么也没学到,并继续在其他地方犯同样的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2012-06-13
  • 1970-01-01
  • 2013-07-15
  • 1970-01-01
  • 2012-11-13
相关资源
最近更新 更多