解析错误:语法错误,第9行C:\ xampp \ htdocs \ php \ dir.php中的意外“文件名”(T_STRING)[关闭]
**php program for reading filenames and filetypes from a dir.**
it shows the syntax error : Parse error: syntax error, unexpected 'filename' (T_STRING) in C:\xampp\htdocs\php\dir.php on line 9
<?php
$dir="C:\xampp\htdocs\php\";
if(is_dir($dir))
{
if($dirref=opendir($dir))
{
while(($file=readdir($dirref))!==false)
{
echo "filename : $file : filetype: ".filetype($dir.$file)."
";
}
closedir($dirref);
}
}
?>
It appears you've escaped the closing quotes on your $dir=
statement. I don't use php in a Windows environment, so I don't know if you can convert all your \
to /
, but if not, you'll want to escape all the \
:
$dir="C:\\xampp\\htdocs\\php\\";
Or use single quotes, which disables escape sequences:
$dir='C:\xampp\htdocs\php\';
Parse errors often indicate that there is a syntax (or string in this case) error in your code, BEFORE the error actually reported by the parser.
The error is on your first line: $dir="C:\xampp\htdocs\php\";
The backslash escapes the quotes.
Escape the backslashes in your code to make it work, like so:
$dir="C:\\xampp\\htdocs\\php\\";
$dir="C:\xampp\htdocs\php\";
Just remove the last '\' and make it
$dir="C:\xampp\htdocs\php";
It will Work..!
Change this:
$dir="C:\xampp\htdocs\php\";
to
$dir="C:\\xampp\\htdocs\\php\\";