Need help getting PHP to translate string as variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Thyme3333
Forum Newbie
Posts: 2
Joined: Wed Jan 14, 2004 1:29 pm

Need help getting PHP to translate string as variable

Post by Thyme3333 »

Code: Select all

<?php
function GetStruct($part_no){
        GLOBAL $struct;
        $part_no_split = split(".",$part_no);
        foreach($part_no_split as $k){
                $k = $k-1;
                $partstring .= "->parts[$k]";
        }
        eval("\$subtype = \$struct . \$partstring . "->subtype";");
        print "$subtype<br>\n";
}

$struct=imap_fetchstructure($mbox,$msg_nr);

$i=1;
while(imap_fetchbody($mbox,$msg_nr,$i)){
        GetStruct($i);
        $i++;
}
?>
-----------------------------------------------------
I'm down to the point where
print "$subtype<br>\n";
displays:

Object->parts[0]->subtype
Object->parts[1]->subtype
Object->parts[2]->subtype

onto the website page. How can I get PHP to
take it literally and show me the value of "subtype"?
Thyme3333
Forum Newbie
Posts: 2
Joined: Wed Jan 14, 2004 1:29 pm

Post by Thyme3333 »

bump :P
Post Reply