fopening files with variable names.... Can't syntax =/

Discussion in 'PHP' started by Meissa, Jan 6, 2007.

  1. #1
    I'm new to PHP, and I'm sure this is a noob question, but after searching everywhere, I have to resort to asking...

    I have a variable who's value is 5 randomly generated numbers:
    $random

    I want to create/open a text file that includes that variable in the name...

    Ideally, to me, the open line would be something like this:


    $file1 = "file1-$random.txt";
    $fhhw = fopen($health1, \'w\')


    I can't seem to get the syntax right on how to insert a variable into the text file's filename that I am trying to create... Can anyone advise?


    Meissa
     
    Meissa, Jan 6, 2007 IP
  2. Choller

    Choller Peon

    Messages:
    388
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Are you trying to do this?

    That is working for me.
     
    Choller, Jan 6, 2007 IP
  3. Meissa

    Meissa Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, that is what I'm trying to do... and I've done that... maybe I had some simple syntax error and assumed that the way I was trying it wasn't working...

    My wanted end result is this:

    Did it name the file it created ---> file1-111.txt?
     
    Meissa, Jan 6, 2007 IP
  4. Meissa

    Meissa Guest

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Wow... (after trying your example)... Thanks for the pointer... I don't know why it didn't work for me the first time I tried it... /shrug...

    /cheers! ^_^
     
    Meissa, Jan 6, 2007 IP