php help - variable for fopen, etc

Discussion in 'PHP' started by adamjthompson, Apr 15, 2006.

  1. #1
    Hello,

    I need my script to create a php file. This file will contain variables with values for each variable, among other content.

    Here is the variable that contains the data that will be written to the file. As you can see, I'm getting the data from a form submission.

    My problem is this: I need the script to excecute the "$_POST["articletitle"]" so it will insert the data from the form submission. the ""$title=.........;" part it should not execute, as it should write that to the php file as the variable.

    $somecontent = '$title="$_POST["articletitle"]"';
    PHP:
    I guess my question is: how do I combine "code to be executued" with "code not to be executed"?

    I hope this makes sense! :p
     
    adamjthompson, Apr 15, 2006 IP
  2. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not entirely sure what you're asking, but hopefully this helps.

    I'll say that $_POST["articletitle"] = 'Google Releases New Calendar';


    $somecontent = '$title='.$_POST["articletitle"];


    Now $somecontent's literal value (what you would get if you echo'ed it out) is: "$title=Google Releases New Calendar"
    Is that what you're looking for?

    --

    If $title had some value and you wanted to output that too (say $title='My Story') you would do one of the following:

    $somecontent = "$title=".$_POST["articletitle"]; (a variable in double quotes will just pass on it's value)
    $somecontent = $title.'='.$_POST["articletitle"];

    Both of these would return "My Story=Google Releases New Calendar"

    -the mole
     
    themole, Apr 15, 2006 IP
    adamjthompson likes this.
  3. adamjthompson

    adamjthompson Well-Known Member

    Messages:
    1,242
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    125
    #3
    Excellent! Just what I needed. Thanks!
     
    adamjthompson, Apr 15, 2006 IP