Re: Help with file reads

From: Andy Hassall (andy_at_andyh.co.uk)
Date: 12/24/03


Date: Tue, 23 Dec 2003 23:31:25 +0000

On 23 Dec 2003 15:14:24 -0800, rascal329@hotmail.com (KB) wrote:

>Newsgroups: alt.php
>
>Thanks for the help guys. I tried to make this work using your
>suggestions but didn't get anywhere. Here is my code in it's
>entirety. It still gives me the same parse error of unexpected "]",
>like it's expecting a variable and doesn't know how to deal with the
>auto incrementing.
>
>
><html>
><head>
><title>imageIndex</title>
></head>
><body>
>
><?
>// image index
>// generates an index file containing all images in a particular
>directory
>
>//point to whatever directory you wish to index.
>//index will be written to this directory as imageIndex.html
>$dirName = "D:\hshome\boone\kbent.com\images\";

 Here's your problem. Inside "" double quotes, \ is used as an 'escape
character'. You use it if you want to use certain characters such as newlines
(\n), or double quotes inside the double quotes, where you use \".

 So the \" at the end actually turns into a literal " _inside the string_, and
now there's no terminating " to actually end the string. What this can then do
is turn the rest of your script into part of the string being assigned to
$dirName!

 It'd then fail here:

  $theFiles[]

 ... on the ], because inside a string, if you're using an array, you have to
give it an array subscript to read from.

 Basically, \ as a directory separator on Windows often causes awkwardness
since it clashes with the escape character. Windows accepts Unix-style '/'
slashes as a directory separator just as well, so either:

(a) Use single quotes (most escape sequences aren't translated in single
quotes):

$dirName = 'D:\hshome\boone\kbent.com\images\';

(b) Escape the \'s (again using \):

$dirName = "D:\\hshome\\boone\\kbent.com\\images\\";

(c) Use / instead:

$dirName = "D:/hshome/boone/kbent.com/images/";
or
$dirName = 'D:/hshome/boone/kbent.com/images/';

-- 
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Relevant Pages

  • Re: Beginners Program
    ... I'd put single quotes aroung the, ... If you are putting "s in a string then it is usually best to use a different ... input file things could go wrong. ... and that the final line of input does end with a newline character. ...
    (comp.lang.perl.misc)
  • Re: Can an "Update" Query insert quotation marks around text?
    ... quotes) is because the software is reacting to the presence of your quotes. ... that text string is delimited by " characters within the software, ... software doubles the " character because that tells the software that the " ... and the last " character marks the end of the text string. ...
    (microsoft.public.access.queries)
  • Re: Re: Vista search including double quote
    ... There is only one occurance of the word Protection in the ... There is no need or reason to enclose one word within quotes in a content ... string that includes a double quote. ... Maybe there's an escape character I can prefix ...
    (microsoft.public.windows.vista.general)
  • Re: Can an "Update" Query insert quotation marks around text?
    ... > quotes) is because the software is reacting to the presence of your quotes. ... > that text string is delimited by " characters within the software, ... > is not the beginning or end of a text string, but a literal " character. ... it's unusual to need to delimit a text string with " characters ...
    (microsoft.public.access.queries)
  • Re: SQL Injection with JDBC
    ... You could try wrapping your test in a PL/SQL block, ... Replace quotes in the user strings with a harmless character, ... public static String requote(String str) ...
    (comp.lang.java.programmer)