Page 1 of 1
Can I "include" text that isn't a file?
Posted: Fri Sep 07, 2007 3:53 pm
by cornrow
For an application I'm writing I have different versions of a page stored in a database. I want to have a few lines of PHP and then spit out the correct version from the database.
If I generate an actual file for each version I can include it no problem. Is there something like include that I can use to import the code from the database.
I can't just echo because then PHP code doesn't get processed. I can't eval() because it doesn't like <?php ?> tags.
Any ideas?
Posted: Fri Sep 07, 2007 4:55 pm
by josa
I guess you can write it out to a temporary file and include that file. I just tried it and it works, but I have no idea how efficient this is.
/josa
Posted: Fri Sep 07, 2007 5:22 pm
by feyd
You can
eval().. it simply isn't recommended.
Posted: Fri Sep 07, 2007 5:32 pm
by shwanky
you can write the data to a php file on the file then include that php file on the fly? But why would you want to store php code in a database? Why not just store the php output in the database.
Posted: Fri Sep 07, 2007 7:33 pm
by Christopher
Strip the <?php tags with something trivial like:
Code: Select all
substr($buffer, 5, strlen($buffer)-7);
eval($buffer);
A database is not necessarily less secure than a file system, so eval() should be fine.
Posted: Fri Sep 07, 2007 8:26 pm
by cornrow
Stripping out the php tags isn't really an option. There are some cases where there might be nested PHP in a textarea that isn't meant to be eval'd. I could write something complicated, but I'm not confident I can think of every possible case.
I'm building a multivariate testing platform, so I the input could be anything. Storing to files is fine, but then I have to deal with permissions and such. I guess if there's no clean option, that's what I'll do.
Tynan