eddy556 Posted June 12, 2007 Share Posted June 12, 2007 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 More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 $directory = 'C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Media\' . $letter; Link to comment https://forums.phpfreaks.com/topic/55275-solved-unexpected-t_string/#findComment-273201 Share on other sites More sharing options...
per1os Posted June 12, 2007 Share Posted June 12, 2007 $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. Link to comment https://forums.phpfreaks.com/topic/55275-solved-unexpected-t_string/#findComment-273203 Share on other sites More sharing options...
eddy556 Posted June 12, 2007 Author Share Posted June 12, 2007 woah that was the quickest reply ever! thanks Link to comment https://forums.phpfreaks.com/topic/55275-solved-unexpected-t_string/#findComment-273206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.