Page 1 of 1

Basic php question (string concatenation )

Posted: Mon Aug 24, 2009 2:02 pm
by kutchbhi
Hi

This is what I have -

Code: Select all

 
$newfile1 = uniqid (true).".html" ;
    $newfile = "categories\books\".$newfile1 ;  //This is the important line
    $file = fopen ($newfile, "w"); 
    fwrite($file, $output); 
 
    fclose ($file);  

I want to create a file in a particular folder .This doesn't works
However if I change

Code: Select all

 
$newfile = "categories\books\".$newfile1 ;
to

Code: Select all

 
$newfile = "categories\books\foo";
or

Code: Select all

 
$newfile = $newfile1 ;
It works . Can someone tell me whats wrong in the original code ?

I hope its clear from the code what I am trying to do.

Thanks

Re: Basic php question (string concatenation )

Posted: Mon Aug 24, 2009 2:18 pm
by Darhazer
\" is an escape character and it becomes just ". So you receive a parse error
you have to escape the \ with \\

Code: Select all

   $newfile = "categories\books\\".$newfile1 ;  //This is the important line

Re: Basic php question (string concatenation )

Posted: Mon Aug 24, 2009 2:23 pm
by kutchbhi
Thanks! that was it.
thread can be closed/deleted