tags:

views:

139

answers:

6

I just want to know if it's possible. How do I save an html page and all of its contents to a database? like for example, I have a database wherein it consists all HTML pages.

Just want to know if its possible. And how to retrieve it too. We're using PHP as our language.

Thank you.

A: 

Assuming MySQL, here is the way to connect to the database and write data into it.

PHP and MySQL

Chathuranga Chandrasekara
i'm sorry what i meant was the content of the html page. like for example: I have a news article that i want to save all of its contents (assuming i also made the news article). in the page, there's a button below that saves all of it into a database. is that possible?
kath
A: 

HTML is just text. You can tore it in a database in a TEXT field.

There are plenty of DBMS you can use and plenty of ways to do it.

You can have a look at the PDO extension to directly consume a MySQL or SQlite connection for instance. You can also use an ORM like Doctrine

Benoit Vidis
+1  A: 

Well, you'll need to:

  • Grab that page by using a HTTP request, just like your browser does
  • Parse that HTML to find external resources (script, img, object, etc)
  • Grab those external resources
  • Save all them on your database into a BLOB field
  • Optionally alter your original HTML document, to change that resources location
Rubens Farias
A: 

If you are trying to save the final results of your PHP script (ie. what is sent to the browser) you will need to look into Output Buffering.

Dominic Barnes
A: 

As others already suggested, yes its possible to save HTML pages inside databases like mysql or sqlite etc. Another way you can perceive "databases" is flat files. Therefore, just like web crawlers or tools like wget/curl that crawls(and download) pages to disk, you can program something like that in PHP (using libraries such as curl) and save those pages to your disk. How to retrieve?? just display them with web browser OR do normal opening of file , display the contents and closing the file, all with PHP.

ghostdog74
A: 

Is this what you are trying to do? http://www.phpfreaks.com/forums/index.php?topic=219271.0 You can simply store the $out in the db instead of saving as html

abel