Skip to content
PHP Logo

What is the correct method to read and store the content of a webpage in an array in PHP?

To read and store the content of a webpage in an array in PHP, you can use the file_get_contents() function to retrieve the webpage content and then use the explode() function to split the content into an array based on a delimiter. This allows you to easily access and manipulate the content as needed.

php
$url = 'https://www.example.com'; // URL of the webpage
$content = file_get_contents($url); // Get the content of the webpage
$contentArray = explode("\n", $content); // Split the content into an array based on new lines

// Now you can access and manipulate the content stored in the $contentArray variable