How I parsed sitemap.xml to save the links in database and make the sitemap dynamic in laravel
Manish Chaudhary
Posted on June 28, 2021
Below is the code snippet I used for this.
$xmlString = file_get_contents(public_path('sitemap.xml'));
$xmlObject = simplexml_load_string($xmlString);
$json = json_encode($xmlObject);
$phpArray = json_decode($json, true);
$usLinks = array_filter($phpArray['url'], function($linkData) {
return strpos($linkData['loc'], '/us/') != false;
});
$usLinks = array_values(array_map(function($linkData) {
return ['status' => 1, 'link' => $linkData['loc'], 'priority' => $linkData['priority']] ;
}, $usLinks));
array_unshift($usLinks, ['status' => 1, 'link' => 'https://sugarwish.com/', 'priority' => 1.00]);
\App\DB\Sitemap::insert(
$usLinks
);
💖 💪 🙅 🚩
Manish Chaudhary
Posted on June 28, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024