Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.