images = array(); // Danh sách hình ảnh $this->setmaxImages(3); } // Thiết lập danh sách hình ảnh public function setmaxImages($maximg) { $this->maximg = $maximg; } public function insertImages($html,$images) { $this->images = $images; // Tìm tất cả các thẻ trong chuỗi HTML preg_match_all('/.+?<\/h[1-6]>|

.+?<\/p>/', $html, $matches); $headers = $matches[0]; $imageIndex = 0; foreach ($headers as $header) { if ($imageIndex < $this->maximg) { // Đây là một thẻ , hãy chèn hình ảnh vào đây $imageToInsert = "\n".'

'; $html = substr_replace($html, $imageToInsert, strpos($html, $header) + strlen($header), 0); } $imageIndex++; } return $html; } }