PHP code example of alexoliverwd / sitemap-parser
1. Go to this page and download the library: Download alexoliverwd/sitemap-parser library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alexoliverwd / sitemap-parser example snippets
$entries = Parser::parser('https://example.com/sitemap.xml');
// or
$entries = Parser::parser('/path/to/local/sitemap.xml');
use AOWD\SitemapParser\Parser;
use AOWD\Exceptions\ParserException;
try {
// Parse a sitemap
$entries = Parser::parser('https://example.com/sitemap.xml');
// Access the parsed entries
foreach ($entries as $entry) {
echo "URL: " . $entry['location'] . "\n";
echo "Last Updated: " . $entry['updated'] . "\n";
}
} catch (ParserException $e) {
echo "Error: " . $e->getMessage();
}
[
'location' => 'https://example.com/page',
'updated' => '2023-01-01T12:00:00+00:00'
]