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
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Nov 24, 2004 5:18 pm
hi people,
i have a module script which takes infos for modules from db. i have dynamic content in some modules so i have written it with php codes so these codes are saved in db. how can i run them after i include it like this..
Code: Select all
<?php
function load_modules() {
$this->moduleblock = file_get_contents('module.htm');
$blocks = '';
foreach ($this->modules as $module) {
$srch = array("{{MODULE_ID}}","{{MODULE_NAME}}", "{{MODULE_CONTENT}}");
$rplc = array($module['mod_id'], $module['mod_name'], $module['mod_content']);
$tmp = str_replace($srch, $rplc, $this->moduleblock);
$blocks .= $tmp;
}
$this->file = str_replace("{{PAGE_MODULES}}", $blocks, $this->file);
}
?>
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Nov 24, 2004 5:21 pm
oh by the way, i forgot to mention that the content is $module['mod_content'] and for example it has dynamic infos for some modules like :
Code: Select all
Hello today is : <?php echo date("d-m-Y");
so what should i do to make it shown as
thank you..
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Wed Nov 24, 2004 5:31 pm
eval()
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Nov 24, 2004 5:34 pm
ok, i thought the same but. how to eval? it's the problem. iit's too late and i'm confused so my brain doesn't work anymore? any ideas?
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Wed Nov 24, 2004 10:38 pm
umm use preg_match to find code between <? and ?> then run eval() on it....
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Thu Nov 25, 2004 2:33 pm
ok but then.. what about other parts of this content???
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Thu Nov 25, 2004 3:06 pm
hmm.. i think i can't get this work, i have to make it file-based or something..
what do you think?
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Thu Nov 25, 2004 3:23 pm
im not very familiar w/ eval, i never use it. but i dont see an easy way to drop in and out of php using eval
maybe this will work?
its not very efficient, but i cant think of a better way at the moment
Code: Select all
$tmpfname = tempnam('/tmp', 'tmp_code');
$fp = fopen($tmpfname, 'w');
fwrite($fp, $php_db_code);
fclose($fp);
include ($tmpfname);
unlink($tmpfname);
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Thu Nov 25, 2004 3:26 pm
i tried it but if you look at my code i will replace the content with {{MODULE_CONTENT}}... so i cannot include it..
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Thu Nov 25, 2004 4:17 pm
Something like
Code: Select all
<?php
function modify_stuff($code) {
$code=str_replace("stuff", "{{MODULE_CONTENT}}", $code);
return($code);
}
$tmpfname = tempnam('/tmp', 'tmp_code');
$fp = fopen($tmpfname, 'w');
modify_stuff($php_db_code);
fwrite($fp, $php_db_code);
fclose($fp);
include ($tmpfname);
unlink($tmpfname);
?>
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Thu Nov 25, 2004 4:53 pm
no way, this is not a good idea and inefficient. i have to find another way to create dynamic modules...
btw, thanx for your examples people...
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Thu Nov 25, 2004 6:00 pm
mudkicker wrote: no way, this is not a good idea and inefficient. i have to find another way to create dynamic modules...
btw, thanx for your examples people...
thats what i was about to suggest