Executing php from DB output |
[eluser]theswede[/eluser]
Hi all, This is what I want to do: I have a site that has "static pages" (Header/Footer the same + "static pages" from db). In the db-tables I store HTML, I also wish to store executable PHP code. Why? What I'd like to do is to be able to use the site_url() in my img-tags making the site more flexible in case it does not reside at the root level of my web-host. How to accomplish this? Alternate solutions? Thanks in advance
[eluser]theswede[/eluser]
Wow, that was an insanely fast reply. Thank you so much walesmd, you have no idea how much this helps! MODS: Please close this thread.
[eluser]theswede[/eluser]
Hmm, is there any other clever way to include images (not through css)? I don't want to use absolute links.
[eluser]Derek Allard[/eluser]
Code: <img src="/images/pic.jpg" /> vs Code: <img src="images/pic.jpg" /> notice the extra "/" at the front?
[eluser]theswede[/eluser]
By absolute links I mean links that do not start with a preceding "/". If the application is located in a subdirectory of the web-root I'd have to use links relative to the web-root to access them thus making the application less flexible, less movable. www.webroot/monkey <-- Application 1 www.webroot/coffee <-- Application 2 www.webroot/images <-- Shared resource, not wanted So, I have 2 choices: * Including "/monkey" in all my img-paths, making the application less movable * Storing my images close to the web-root, making the application moveable but the web-root messy. Are there any better ways to solve this?
[eluser]freaksauce[/eluser]
Do you mean you would prefer to have an images directory in each application like: application1->images application2->images ? Could you just use site_url() ? <img src="<?=site_url()/images/pic.jpg" /> Then no matter which application you are using it will look in the images dir for that application?
[eluser]theswede[/eluser]
freaksauce: Yes, using site_url('whatever') would be preferred, but I can't since the HTML is stored as a huge string in the DB
[eluser]Michael Wales[/eluser]
Do a str_replace or a preg_replace on the data coming from the DB. Change all instances of /images/ to <?= site_url(); ?>/images/
[eluser]Michael Roper[/eluser]
Michael, you mention using eval() to parse the db content, but at what point would you do that? In my model or my view, if I do something like the following: Code: //$data['content'] = $row['body']; <- thats what i usually just do Code: Parse error: syntax error, unexpected '<' in C:\www\application\views\main.php(43) : eval()'d code on line 1 |
Welcome Guest, Not a member yet? Register Sign In |