Forum Moderators: coopster

Message Too Old, No Replies

How to concatenate a filename

         

Da_riPPer

8:29 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



How would one go about doing the following:

if (file_exists('conent'.'\'.$col_value.'.xml'))
seeing that the '\' part creates an error, and
that you cannot use '\\' in the filename?

For example, what I need is for the filename to
look like this:

conent\Fear.xml

where the Fear is found in col_value?

Thanks

keno

9:10 pm on Oct 17, 2005 (gmt 0)

10+ Year Member



It's been a while since I used it, but in C the double \\ backslash should work. Give it try!

I've never done anything in PHP :-)

coopster

7:21 pm on Oct 18, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Da_riPPer.

keno is correct [php.net] when you are using single-quoted strings in that if the backslash needs to occur before a single quote or at the end of the string, you need to double it. Note that if you try to escape any other character, the backslash will also be printed! So usually there is no need to escape the backslash itself. For example:

print 'hello\there'; // prints hello\there 
print 'hello\'there'; // prints hello'there
print 'hello\\'; // prints hello\

Just remember that first sentence ... if the backslash needs to occur before a single quote or at the end of the string, you need to double it.

Be sure to read on about the double-quoted syntax as well!