Jump to content


Photo

Executing PHP Function through echo'd variable


  • Please log in to reply
11 replies to this topic

#1 mysticssjgoku4

mysticssjgoku4
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 May 2006 - 01:27 AM

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

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

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

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

#2 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 14 May 2006 - 01:35 AM

look at the exec() function
[a href=\"http://www.php.net/exec\" target=\"_blank\"]http://www.php.net/exec[/a]

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#3 mysticssjgoku4

mysticssjgoku4
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 May 2006 - 01:54 AM

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.

#4 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 14 May 2006 - 01:56 AM

instead of echo
use exec

simple as that

exex($skin[content]);

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#5 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 14 May 2006 - 01:57 AM

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]



#6 mysticssjgoku4

mysticssjgoku4
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 May 2006 - 02:08 AM

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
$skin['content'] .= "include('pages/page_$pagename.src');";

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


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

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


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

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

Thank You once again!

#7 _will

_will
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 14 May 2006 - 05:12 AM

try
$skin['content'] .= "eval(include('pages/page_$pagename.src'));";



#8 mysticssjgoku4

mysticssjgoku4
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 May 2006 - 06:51 AM

That didn't work and I get an error with that

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


#9 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 May 2006 - 07:14 AM

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.

#10 mysticssjgoku4

mysticssjgoku4
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 May 2006 - 04:38 PM

[!--quoteo(post=373675:date=May 14 2006, 02:14 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ May 14 2006, 02:14 AM) View Post[/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\" /]

#11 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 14 May 2006 - 04:56 PM

[!--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 do.
$skin['content'] = "include('pages/page_$pagename.src')";
eval($skin['content']);


#12 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 14 May 2006 - 05:23 PM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users