LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2006, 07:20 AM   #1
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
Use PHP code inside itself


Hi,

I am trying to create a site that will be easy to use for the administrator of the site. My current idea is to have certain pages stored in the MySQL database with all the html and so on, which will be editable through forms on the side itself.

The problem is that I want to be able to use php code as well. For example, I have a string "<div>here is some php <? echo \"asd\"; ?></div>", this is then stored in the database, and will be editable for the admin. The problem is: how can I insert this into the page, using PHP, but still make the server run the php code? A simple 'echo $code' won't work obviously. I have looked at eval() but that would require me to use ONLY php code and get rid of all the html.

Any ideas?
 
Old 04-03-2006, 07:44 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

I don't think PHP has a way to do what you want. But why are you using a database? If it was files, you could just use "include" or "require". The only way I can think of would be to read the page from the database, write it to a disk file, and then use require.

Maybe there's another way, but I think it would be complicated. Why not use just files?

Best regards,
Guttorm.
 
Old 04-03-2006, 07:51 AM   #3
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Well I have been thinking about using files instead. It's just that I would like it if I can change the content directly on the site itself. I guess I can accomplish this by saving and reading from files. Guess I'll have to work with it that way.
 
Old 04-03-2006, 08:06 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
i considered doing this exact same thing before.. and the only answer i could come up with was..
* read the page from the db
* write the data from db to a new file
* redirect the browser to the new page
* after user leaves page delete the file

seemed like alot of work and it still did not really do what i was hoping for..

however it is a good idea, and could be pretty useful.. though you could just give an admin access to modify the necessary files..
 
Old 04-03-2006, 08:33 AM   #5
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Original Poster
Rep: Reputation: 50
Well I still need the db since I do not only have the html in there but also the hiearchy of the different pages for navigation. But what I did was that I have created a "edit pages"-page which takes an id of a page as argument, fetch all data from the db and opens the file page/<i>name</i>.src and put the content in a textarea. When the user submits I just update the db with the navigation data and update the file with the new content. So the html never touches the database actually.

This way I can give the admin a choice of either edit the pages in the site, or by modifying the files in the page-directory. The reason why I want to have the editing aviliable on the site itself is mostly because the admin after me is not familiar with *BSD or anything other the Windows actually. And I thought it would be easier for both me and him to just put all the content on the site, instead of requiring him to learn how to navigate and edit files in a UNIX environment.

But my solution works fine for now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
execute shell command inside of c code? khucinx Programming 6 10-26-2010 09:30 PM
Using [code] inside of [color] results in very small text scuzzman LQ Suggestions & Feedback 1 03-28-2005 02:14 AM
PHP has an easter egg inside (image code) micxz Linux - Software 0 09-18-2004 08:41 PM
run shell command inside of c code? khucinx Programming 2 05-17-2004 10:04 AM
how to invoke a linux command inside a java code ? kusum Linux - Software 2 11-23-2003 01:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration