Open HTML in PHP SDK

Use REST API to open and read HTML files programmatically in PHP

Easily open HTML documents with just a few lines of PHP code. Our PHP library will provide you with everything you need to access HTML document content programmatically.

View code snippet

Open a HTML file in PHP

The task of reading HTML documents is the task of reading hierarchical data structures within the DOM model. This implies knowing the format of each individual HTML data element, including all of its possible child elements and attributes.

Our PHP library is a cloud-based solution that will allow you to open HTML files for reading and writing easily. This distributed approach gives you flexibility in software development using PHP language, as all resource-intensive HTML document processing will take place on Aspose servers. All you need is to get private keys to access Cloud API in PHP code.

Programmatically read HTML documents in PHP

You can iterate over all elements of a HTML document or you can search for specific elements in a DOM tree. We provide a wide range of PHP functions both for working with the structure of the HTML file and with the data contained in the document nodes.

The following code example will help you quickly figure out how to load a HTML file using PHP and perform some actions on it.

Upload a document you want to access
Run code
use Aspose\Words\WordsApi;

$wordsApi = new WordsApi('####-####-####-####-####', '##################');
$fileName = "Input.html";

$requestFileContent = file_get_contents(realpath(
   __DIR__ . '/../../..') . "/TestData/" . $fileName);
$uploadDocumentRequest = new UploadFileRequest(
    $requestFileContent, $fileName, NULL
);
$wordsApi->uploadFile($uploadDocumentRequest);

$requestParagraph = new ParagraphInsert(array(
    "text" => "Reading and writing to the file in the cloud occurs automatically.",
));
$insertParagraphRequest = new InsertParagraphRequest(
    $fileName, $requestParagraph, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
);
$wordsApi->insertParagraph($insertParagraphRequest);

$downloadDocumentRequest = new DownloadFileRequest(
    $fileName, NULL, NULL
);
$wordsApi->downloadFile($downloadDocumentRequest);
Run code
  
Copy PHP code to the clipboard

How to open HTML PHP REST API

  1. Install Aspose.Words Cloud for PHP
  2. Add a library reference (import the library) to your PHP project
  3. Read a HTML file

Install PHP library to read HTML files

Install 'Aspose.Words Cloud SDK for PHP' from Packagist repository. Just run composer require aspose-cloud/aspose-words-cloud to install the SDK, then use require_once('vendor/autoload.php'); to import it into your project.

As an alternative, you can manually clone Aspose.Words Cloud SDK for PHP source code from GitHub. Please follow these Instructions to quickly get the necessary security credentials and access our REST API.

System Requirements

PHP 7.1 or newer

Refer to the Repository Documentation to see more details.

Other supported file formats

You can open documents in other formats:

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2025. All Rights Reserved.