gpt4 book ai didi

PHP:语法错误,意外的 T_STRING

转载 作者:行者123 更新时间:2023-12-03 02:23:20 26 4
gpt4 key购买 nike

我收到此 PHP 代码的语法错误

syntax error, unexpected T_STRING

它显示第 2 行,即包含行:

<?php  
 include 'config.inc.php';  
 
 // initialization  
 $photo_upload_fields = '';  
 $counter = 1;  
 
 // If we want more fields, then use, preupload.php?number_of_fields=20  
 $number_of_fields = (isset($_GET['number_of_fields'])) ?  
   (int)($_GET['number_of_fields']) : 5;  
 
 // Firstly Lets build the Category List  
 $result = mysql_query('SELECT category_id,category_name FROM gallery_category');  
 while($row = mysql_fetch_array($result)) {  
   $photo_category_list .= <<<__HTML_END

<option value="$row[0]">$row[1]</option>\n  
__HTML_END;  
 }  
 mysql_free_result( $result );    
 
 // Lets build the Image Uploading fields  
 while($counter <= $number_of_fields) {  
   $photo_upload_fields .= <<<__HTML_END  
<tr><td>  
 Photo {$counter}:  
 <input name="photo_filename[]"  
type="file" />  
</td></tr>  
<tr><td>  
 Caption:  
 <textarea name="photo_caption[]" cols="30"  
   rows="1"></textarea>  
</td></tr>  
__HTML_END;  
   $counter++;  
 }  
 
 // Final Output  
 echo <<<__HTML_END  
<html>  
<head>  
<title>Lets upload Photos</title>  
</head>  
<body>  
<form enctype="multipart/form-data"  
 action="upload.php" method="post"  
 name="upload_form">  
 <table width="90%" border="0"  
   align="center" style="width: 90%;">  
   <tr><td>  
     Select Category  
     <select name="category">  
     $photo_category_list  
     </select>  
   </td></tr>  
   <! - Insert the image fields here -->  
   $photo_upload_fields  
   <tr><td>  
     <input type="submit" name="submit"  
       value="Add Photos" />  
   </td></tr>  
 </table>  
</form>  
</body>  
</html>  
__HTML_END;  
?>

我的包含文件如下所示:

<?php  
$mysql_link = mysql_connect("localhost","user","password");
mysql_select_db("db_name") or die("Could not select database");
$images_dir = "photos";
?>

解决方案:

我在代码中隐藏了不可见的 unicode 字符,导致 PHP 解析器提示上述语法错误。

最佳答案

HEREDOC 语法变量的开头和结尾有多个空格;这会导致问题。去掉

后面的空格
<<<__HTML_END

及之后

__HTML_END;

并且您的代码应该可以工作。

另请参阅我在其中找到答案的线程:http://board.phpbuilder.com/board/showthread.php?t=10333424

关于PHP:语法错误,意外的 T_STRING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10783733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com