如何在图像和其他HTML文本格式的mysql数据库中存储php博客文章?

时间:2016-05-08 18:02:29

标签: php mysql regex web mysqli

我正在开发我的php博客项目。如何将博客文章中的图像存储到目录中? 博客文章可能包含强大,斜体,网络链接,列表,图像等。
(我是php初学者。提前致谢。)

1 个答案:

答案 0 :(得分:0)

这里让我告诉你如何做到这一点:

使用

PHP Simple HTML DOM Parser:

LINK:http://simplehtmldom.sourceforge.net/

从链接下载所有图片的示例代码:

注意:以下代码将下载代码中提供的网址上显示的所有图片。

<?php
// Make sure to include the library php file
include('simple_html_dom.php');

//URL To Download Images From
$url = "http://www.google.com/"

// Create DOM from URL or file
$html = file_get_html($url);

// Find all images 
$i=1;
foreach($html->find('img') as $element) { 
$url = $element->src;
$img = "/my_folder/image_".$i.".png";
file_put_contents($img, file_get_contents($url));
$i++;
}
?>