Jump to content

Archived

This topic is now archived and is closed to further replies.

mysticssjgoku4

Executing PHP Function through echo'd variable

Recommended Posts

Hello there,
I'm trying to execute a function such as "include('file.php');" by echoing it through a variable.

Set Before Loading Page:
[code]$skin['content'] .= "<?php include('pages/page_$pagename.src'); ?>";[/code]

In Page:
[code]<td class='nav_body' nowrap>
                                        <br>
                                        <? echo $skin[content]; ?>
                                        <br>
                                    </td>[/code]

Now, I've tried all sorts of things and cannot get this to execute a function while echo'ing it. Nothing has worked, most I've got it to do is echo the text.

If you could please help me out, I would appreciate it greatly!

Thank you very much.

-Ryan

Share this post


Link to post
Share on other sites
look at the exec() function
[a href=\"http://www.php.net/exec\" target=\"_blank\"]http://www.php.net/exec[/a]

Share this post


Link to post
Share on other sites
I don't understand how I'm supposed to use that.
I don't even think it would work for what I'm trying to achieve :-\.

I want it so that I can echo text and/or call a function through a variable.
Have any examples?

Thanks.

Share this post


Link to post
Share on other sites
instead of echo
use exec

simple as that

[code]exex($skin[content]);[/code]

Share this post


Link to post
Share on other sites
You want to use eval():

[a href=\"http://us2.php.net/manual/en/function.eval.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.eval.php[/a]

Share this post


Link to post
Share on other sites
Thank you, eval worked perfectly.

[img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]


One thing, I'm not sure if it's my fault or what:

I put this in

Index.php
[code]
$skin['content'] .= "include('pages/page_$pagename.src');";
[/code]

Page Included
[code]
<?
    $skin['title'] = "News";
?>


<p align='center'>
<table width='95%' border='1'>
    <tr>
        <td>

        </td>
    </tr>
    <tr>
        <td>
            CENSORED<br>
        </td>
    </tr>
</table>
</p>

[/code]

Template
[code]<td class='nav_body' nowrap>
                                        <br>
                                        <? eval($skin[content]); ?>
                                        <br>
                                    </td>[/code]

Doesn't set the value $skin['title'] to "News" as it should above.

Thank You once again!

Share this post


Link to post
Share on other sites
try
[code]
$skin['content'] .= "eval(include('pages/page_$pagename.src'));";

[/code]

Share this post


Link to post
Share on other sites
That didn't work and I get an error with that

[code]
Parse error: parse error, unexpected $end in C:\HLServer\Apache2\htdocs\dba\skins\default\style_layout.src(63) : eval()'d code(1) : eval()'d code on line 1
[/code]

Share this post


Link to post
Share on other sites
You might want to watch your tongue when posting on the forums. Some people may take offence. I would edit your previous post if I where you.

Share this post


Link to post
Share on other sites
[!--quoteo(post=373675:date=May 14 2006, 02:14 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ May 14 2006, 02:14 AM) [snapback]373675[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You might want to watch your tongue when posting on the forums. Some people may take offence. I would edit your previous post if I where you.
[/quote]

Not only is it an example, it's a quote from television. If it was able to be air'd I don't believe anyone will take offense to it and would rather laugh at it. Good Day, and thank you for going off topic while not providing me any help. I can see the relevance you must make amongst the community.

Now aside from all that, does anyone have any better ideas? [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I don't believe anyone will take offense to it[/quote]
Im telling you that I [b]do[/b].
[code]
$skin['content'] = "include('pages/page_$pagename.src')";
eval($skin['content']);
[/code]

Share this post


Link to post
Share on other sites
Well, I don't really see what you're doing exactly since you don't show where $skin['title'] is echoed/printed.

Think about using a template engine like Smarty instead.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.