简体   繁体   中英

How do I save an html page to a database?

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.

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

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

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

PHP and MySQL

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

如果您要保存PHP脚本的最终结果(即发送到浏览器的内容),则需要查看Output Buffering

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM