Create string from Text and Variables

Discussion in 'PHP' started by blackburn2413, Nov 8, 2010.

  1. #1
    Hey everyone, I need to make a string from a list of predefined static text and variables. This will be used to generate a config.php script for my new script.

    Basically here is where I am at:

    $config = "<?php $dbname = ".$enteredname."; $dbuser = ".$entereduser."; $dbpass = ".$enteredpass."; ?>";

    for the page before this I have a form that saves the variables $enteredname, $entereduser, and $enteredpass. In that string $config, the only strings I want replaced are the "entered" ones from my form. The others I actually want to leave as plain text for my config.php page is right.


    Any ideas?
     
    blackburn2413, Nov 8, 2010 IP
  2. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this

    $config = "<?php\n\t\$dbname = \"".$enteredname."\";\n\t\$dbuser = \"".$entereduser."\";\n\t\$dbpass = \"".$enteredpass."\";\n?>";
    PHP:
     
    bencummins, Nov 8, 2010 IP
  3. blackburn2413

    blackburn2413 Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3

    No go, when using that syntax, the output of the page leaves me with a config.php files that contains:

    <?php
    	$dbname = "";
    	$dbuser = "";
    	$dbpass = "";
    ?>
     
    
    PHP:
     
    blackburn2413, Nov 9, 2010 IP
  4. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the formats right, im guessing you need to change the "entered" variables to pull from the previous form... i.e $_POST["name"] etc
     
    bencummins, Nov 9, 2010 IP
  5. blackburn2413

    blackburn2413 Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    Didnt even notice that. Changed and updated some variable names and got it working. Thank you much!
     
    blackburn2413, Nov 9, 2010 IP