1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php value in an echo request problem

Discussion in 'PHP' started by DK42, Jul 11, 2009.

  1. #1
    Hi all

    Quick question, its stumped me, so am hoping someone can help.

    If I want to include a file by way of PHP include, so I would have the following

    <?php include (TEMPLATEPATH.'/scripts/comment-templates/FILENAME.php');?> 
    Code (markup):
    So that works. Now I want to have FILENAME as a variable. So its been set though a different array (it works, I can echo the name correctly with this)

    $mb_comment_template_name
    Code (markup):
    How can I join those together? So $mb_comment_template_name replaces FILENAME in the include lines.

    I cant get it to read the variable, it just spits out the variable name not its value.

    Thanks to anyone who can help!!!:)
     
    DK42, Jul 11, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    you mean u want to actually include the file $mb_comment_template_name ??
     
    Bohra, Jul 11, 2009 IP
  3. Sam Designs

    Sam Designs Active Member

    Messages:
    474
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    <?php include (TEMPLATEPATH."/scripts/comment-templates/$mb_comment_template_name.php");?>

    That should replace FILENAME with $mb_comment_template_name.

    You cannot use $variables in a string enclosed with ' and '. It needs to be " and ".

    If you wanted to use ' and ', you could use the following:

    <?php include (TEMPLATEPATH.'/scripts/comment-templates/'.$mb_comment_template_name.'.php');?>
     
    Sam Designs, Jul 11, 2009 IP
    DK42 likes this.
  4. DK42

    DK42 Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes thats right. So I can define the value of $mb_comment_template_name somewhere else on the site. So if I defined it as "melon" the file location would come back as:

    <?php include (TEMPLATEPATH.'/scripts/comment-templates/melon.php');?>

    Its gonna be a different value due to user selections, so I cant just hard copy it in. Hope that makes sense!
     
    DK42, Jul 11, 2009 IP
  5. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #5
    try what Sam Designs posted will do what u want
     
    Bohra, Jul 11, 2009 IP
  6. DK42

    DK42 Peon

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That works! Thank you Sam and Bohra, really helped me out! Thank you very much!!!!!!!
     
    DK42, Jul 11, 2009 IP
  7. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes, remember that single quoted strings do not expand variables, whereas double quoted strings do.
     
    wd_2k6, Jul 11, 2009 IP