Jump to content

Use a function inside eval()


axtg86

Recommended Posts

Hi all,

 

It has been one of those days. Looking at two lines of code all day, not being able to solve the issue. Here is what I'd like to do.

 

Let's say I have three pages (simplified example).

 

content.php

<? echo "hello world"; ?>

 

fillcontent.php

function getContent($page) {
$filestream = @fopen("./content/".$page.".php", "r");
$filecontent = @fread($filestream, @filesize("./content/".$page.".php"));
	$brace_o = "("; // Convert to eval() friendly character
	$brace_c = ")"; 
	$semi = ";";
	$ques="?"; 
	$php_open="<${ques}php"; 
	$php_close="${ques}>"; 
	eval("$php_closestrtoupper${brace_o}$filecontent${brace_c}${semi}$php_open");
	// = eval("?>strtoupper($filecontent);<?"); 
	// I'm closing php tag first, because $filecontent already contains these (prevent repetition)
}

 

index.php

<? getContent('content'); ?>

 

But this throws me the following error:

Parse error: parse error in ../fillcontent.php(109) : eval()'d code on line 1

 

I have no clue what is causing this. So any new directions are much appreciated! For those curious (might help): I'd like to include user generated pages (which might include PHP) into a template file and instead of the strtoupper() mentioned above I'd like to include a markdown() function. Making it possible for users to use Wiki mark-up (== header ==).

 

Best regards!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.