Convert the value of an object into a php variable

Discussion in 'PHP' started by klare, Jan 12, 2013.

  1. #1
    Hi,

    I try to write the value of a html tag to a php variable. I have this code but it won't work as I thought. Tha value of {tag1} is 25.

    $x = new stdClass;
    $x->foo = "{tag1}";
    $foo = $x->foo;
    ob_start();
    $v = var_export($foo, true);
    echo $v;
    $stdClass = ob_get_contents();
    ob_end_clean();
    $age = $stdClass;


    When checking the output, the name and not the value is written.

    echo $age[0] <------ givs ' and not 2
    echo $age[1] <------ givs { and not 5

    How can I get the $age to contain the value 25?

    Thanks
     
    klare, Jan 12, 2013 IP
  2. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    replace $x->foo = "{tag1}"; with $x->foo = 25;
     
    ogah, Jan 12, 2013 IP
  3. klare

    klare Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    {tag1} is the html hook I use in the template to extract a field from a database so I cannot write anything else than {tag1}

    I want to use the int/number from database in a calculation and since {tag1} is treated as an object I has to get the value into another variable.
     
    klare, Jan 12, 2013 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    {php}
    $variable = "$this->get_template_vars('tag1')";
    {/php}
    PHP:
     
    Last edited: Jan 12, 2013
    MyVodaFone, Jan 12, 2013 IP