Jump to content

[SOLVED] Unexpected T_STRING


eddy556

Recommended Posts

Hi, I'm getting the error:

 

Parse error: syntax error, unexpected T_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\index.html on line 15

 

and can't work out what's going on.  Here is my code:

<?php

include ("header.php");

if(isset($_GET['letter'])) {
$letter = $_GET['letter'];
}
else
{
$letter = "A";
}


$directory = "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Media\" . $letter;
$path = "Media/" . $letter . "/";

if ($handle = opendir($directory)) 
{
while (false !== ($file = readdir($handle))) 

{
		if ($file != "." && $file != "..") 
		{

			$test = substr($file, -4);

				if ($test == ".mp3" | $test == ".wma")

				{	

				$_filename = $path . $file;
				$filename = addslashes($_filename);

				echo "<a class='body' href='$filename'>$file</a></br>";

				}

		}







}
closedir($handle);
}

include ("footer.php");
?>

 

with line 15 being: $path = "Media/" . $letter . "/";

 

Thanks for your help  :)

Link to comment
https://forums.phpfreaks.com/topic/55275-solved-unexpected-t_string/
Share on other sites

$directory = 'C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Media\' . $letter;

 

An alternative to that is:

$directory = "C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Media\\" . $letter;

 

What was happening is \ is considered the escaping character, so if you wanted to use double quotes in the string above you would use \ before the quote you want to appear in the string. What was happening was that was escaping the ending quote, which in turn threw a syntax error because there was no end to that string declaration. So instead you have to escape each \ as seen above or use single quotes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.