3v4l.org

run code in 300+ PHP versions simultaneously
<?php function generateSitemap($urls) { $xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; foreach ($urls as $url) { $encodedUrl = htmlspecialchars($url, ENT_QUOTES | ENT_XML1, 'UTF-8'); $xml .= " <url>" . PHP_EOL; $xml .= " <loc>{$encodedUrl}</loc>" . PHP_EOL; $xml .= " <lastmod>" . date('Y-m-d') . "</lastmod>" . PHP_EOL; $xml .= " <changefreq>weekly</changefreq>" . PHP_EOL; $xml .= " <priority>0.8</priority>" . PHP_EOL; $xml .= " </url>" . PHP_EOL; } $xml .= '</urlset>'; return $xml; } // Example usage $urls = [ 'https://example.com', 'https://example.com/page1', 'https://example.com/page2?param=value&other=another', ]; header('Content-Type: application/xml'); echo generateSitemap($urls); ?>
Output for 8.2.0 - 8.2.27, 8.3.0 - 8.3.16, 8.4.1 - 8.4.3
<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>https://example.com</loc> <lastmod>2025-01-11</lastmod> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> <url> <loc>https://example.com/page1</loc> <lastmod>2025-01-11</lastmod> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> <url> <loc>https://example.com/page2?param=value&amp;other=another</loc> <lastmod>2025-01-11</lastmod> <changefreq>weekly</changefreq> <priority>0.8</priority> </url> </urlset>

preferences:
59.49 ms | 408 KiB | 5 Q