0

So basically I have this "gallery" page of mine which works by having a mysql database that stores the references and file names of the images i'm uploading. I also have "albums" where similarly categorized pictures are in there. My question is, I would like php to generate me an html file whenever I would like to have a new album (since this albums are just href's to another html page that contains the images). I know how to use fopen() and fwrite() but my problem is, how can I create a string that would be able to hold a WHOLE HTML DOCUMENT formatting? That doesn't require me to escape double quotes and such anymore?

5
  • just like this $your_data = fetch_from_mysql(); and $html = '<html><body><div>'.$your_data.'</div></body></html>'; now create that function and return the data as you want to show/store. Commented Sep 25, 2016 at 4:53
  • But my problem is, I do have lots of double quotations in my HTML General Format, I'm asking if there's anyway that I can do so that I wouldn't have the need to escape such double quotes anymore? Anw, thanks for that! ;D Commented Sep 25, 2016 at 4:54
  • Your data may have double quotation, it does not matter. Just use them inside the single quota. Commented Sep 25, 2016 at 4:56
  • 1
    @FrayneKonok No, that's not appropriate. Use htmlspecialchars() around any arbitrary data used in the context of HTML. Commented Sep 25, 2016 at 6:56
  • @Brad, Thanks for the message.. Commented Sep 25, 2016 at 7:01

1 Answer 1

2

What you really want is a templating engine, such as Smarty.

Next, you can write static HTML files to disk if you want... but consider outputting them dynamically. Use rewrite rules to point your galleries at a single PHP scripts that generates these. It tends to be more manageable.

(There are situations where static files can be useful... such as distributing to CDNs and what not. But I'm guessing that for your case, a dynamic page is sufficient.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.