Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Either edit the $sites array, or make a sites.txt file in the same directory and
- * comment out the $sites array and uncomment the line below
- */
- $sites = array(
- 'https://www.androidcentral.com/',
- 'https://handsetexpert.com/'
- );
- // $sites = explode("\n", file_get_contents(__DIR__ . '/sites.txt'));
- $urls = [];
- foreach ($sites as $site) {
- $urls = array_merge($urls, fetchUrls(rtrim($site, '/') . '/sitemap.xml'));
- }
- $counts = [
- 'match' => 0,
- 'no_match' => 0,
- 'perc' => 0
- ];
- foreach ($urls as $url) {
- if (preg_match('/(.*?)(\-|_)vs(\-|_)(.*?)/i', $url) == true) {
- $counts['match']++;
- } else {
- $counts['no_match']++;
- }
- }
- $counts['perc'] = round(($counts['match'] / ($counts['match'] + $counts['no_match'])) * 100, 2) . '%';
- print_r($counts);
- function fetchUrls(string $sitemapUrl)
- {
- $content = file_get_contents($sitemapUrl);
- preg_match_all('/<loc>(.*?)<\/loc>/', $content, $urls);
- $final = $urls[1] ?? [];
- foreach ($final as $url) {
- if (stripos($url, 'sitemap') !== false) {
- $final = array_merge($final, fetchUrls($url));
- }
- }
- return $final;
- }
Advertisement
Add Comment
Please, Sign In to add comment