items[] = array( 'loc' => $loc, 'priority' => $priority, 'changefreq' => $changefreq, 'lastmod' => $lastmod, ); } /** * @param string $filename * @return mixed */ function build($filename = null) { $xml = '' . "\n"; $xml .= '' . "\n"; foreach ($this->items as $item) { $item['loc'] = htmlentities($item['loc'], ENT_QUOTES); $xml .= "\t\n\t\t{$item['loc']}\n"; if (!empty($item['lastmod'])) { $xml .= "\t\t{$item['lastmod']}\n"; } if (!empty($item['changefreq'])) { $xml .= "\t\t{$item['changefreq']}\n"; } if (!empty($item['priority'])) { $xml .= "\t\t{$item['priority']}\n"; } $xml .= "\t\n"; } $xml .= "\n"; if (!is_null($filename)) { return file_put_contents($filename, $xml); } else { return $xml; } } }