-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsitemap.php
More file actions
59 lines (47 loc) · 1.63 KB
/
Copy pathsitemap.php
File metadata and controls
59 lines (47 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
function extractURLs($pageURL) {
$pageContent = file_get_contents($pageURL);
$dom = new DOMDocument;
libxml_use_internal_errors(true);
$dom->loadHTML($pageContent);
libxml_clear_errors();
$urls = array();
$links = $dom->getElementsByTagName('a');
foreach ($links as $link) {
$url = $link->getAttribute('href');
if ($url && $url !== '#') {
$urls[] = $pageURL . $url;
}
}
return $urls;
}
function isLink($string) {
$pattern = '/^(https?:\/\/)?([\w\d\-]+\.)+[\w\d\-]+(\/[\w\d\-./?=#%&]*)?$/i';
return preg_match($pattern, $string);
}
if(!isset($_GET['url'])){
echo "Add your Website URL to the url parameter.";
echo "For Example :- https://wholly-api.sh20raj.repl.co/sitemap.php?url=https://github.com/";
echo "Get more on <a href='../'>Wholly-API</a>";
} else {
header("Content-Type: application/xml; charset=utf-8");
// Example: Extract URLs from the homepage
$pageURL = $_GET['url'];
if (substr($pageURL, -1) === '/') {
$pageURL = rtrim($pageURL, '/');
}
$urls = extractURLs($pageURL);
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach ($urls as $url) {
//if(!var_dump(isLink($url))){continue ; }
echo '<url>';
echo '<loc>' . htmlspecialchars($url) . '</loc>';
echo '<lastmod>' . date("Y-m-d") . '</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>1.0</priority>';
echo '</url>';
}
echo '</urlset>';
}
?>