Calling a Variable with a Variable?

Discussion in 'PHP' started by DeluxeEdition, Mar 27, 2007.

  1. #1
    I'm not sure if I'm even asking this question right:

    The website I'm updating is written in PHP an Smarty and since I wouldn't consider myself a programmer in either I'm running into a bit of trouble.

    What I'm trying to do is call an rss feed based on the page title. I was able to get the page title to show up on the tpl page within {php} but I can't seem to set it as a variable. Here's what I'm trying:

    $rss_keyword = echo $this->_tpl_vars['title']
    Code (markup):
    What am I missing?
     
    DeluxeEdition, Mar 27, 2007 IP
  2. SeLfkiLL

    SeLfkiLL Active Member

    Messages:
    85
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    50
    #2
    You can use eval() to execute a string as php.

    However, I am not sure I quite understand what you're trying to do by your description.
     
    SeLfkiLL, Mar 27, 2007 IP
  3. DeluxeEdition

    DeluxeEdition Active Member

    Messages:
    308
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks SeLfkiLL I'm not really sure I understand what your saying either :D

    Say the title of the page is Chocolate and

    echo $this->_tpl_vars['title']
    Code (markup):
    figures that out based on the page title.

    In this case I want to Chocolate to be the $rss_keyword

    So

    $rss_keyword = 'Chocolate' 
    Code (markup):
    Does that help at all
     
    DeluxeEdition, Mar 27, 2007 IP
  4. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You might try:

    
    $rss_keyword = $this->_tpl_vars['title'];
    
    Code (markup):
    The way you have written the code will generate a parse error because you cannot have something equal to the result of an "echo" statement. PHP will complain that it has encountered an "unexpected T_ECHO"
     
    clancey, Mar 27, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    
    $this->_tpl_vars["rss_keyword"] = $rss_keyword;
    echo $this->_tpl_vars["rss_keyword"]
    
    PHP:
    I think you want that ..... then you'll have the rss keyword inplace of the title, and take notice of post above.
     
    krakjoe, Mar 28, 2007 IP
  6. DeluxeEdition

    DeluxeEdition Active Member

    Messages:
    308
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    58
    #6
    krakjoe -

    How would the site know what the title of the page is to use as the rss_keyword with your example? I think I'm missing something.
     
    DeluxeEdition, Mar 28, 2007 IP
  7. DeluxeEdition

    DeluxeEdition Active Member

    Messages:
    308
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Your answer works when I test it with something simple like

    echo $rss_keyword
    Code (markup):
    I just didn't realize it because the RSS Reader I'm using, CARP, is throwing an error. Thanks for everyone's help I may just not be able to pull stories on the fly with carp.
     
    DeluxeEdition, Mar 28, 2007 IP