Basic php question (string concatenation )

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kutchbhi
Forum Newbie
Posts: 12
Joined: Mon Aug 24, 2009 2:00 pm

Basic php question (string concatenation )

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Basic php question (string concatenation )

Post 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
kutchbhi
Forum Newbie
Posts: 12
Joined: Mon Aug 24, 2009 2:00 pm

Re: Basic php question (string concatenation )

Post by kutchbhi »

Thanks! that was it.
thread can be closed/deleted
Post Reply