开发者

how to create site maps from MySQL database?

开发者 https://www.devze.com 2023-02-18 18:31 出处:网络
An MySQL database contain around 1 million information about domain names. how do I create an xml开发者_如何学Go site map from the said database with PHP 10000 domain names in it.and the xml file shou

An MySQL database contain around 1 million information about domain names. how do I create an xml开发者_如何学Go site map from the said database with PHP 10000 domain names in it.and the xml file should be given a sequent name for example sitemap1.xml,sitemap2.xml etc.


You can just write XML and save it using file_put_contents(). So just loop through all your results and split each file at 10.000 items.


You could use DOMDocument. You can use it like this:

$doc = new DOMDocument();
$doc->formatOutput = true;

$r = $doc->createElement( "employees" );
$doc->appendChild( $r );

foreach( $employees as $employee )
{
  $b = $doc->createElement( "employee" );

  $name = $doc->createElement( "name" );
  $name->appendChild(
    $doc->createTextNode( $employee['name'] )
  );
  $b->appendChild( $name );
}

echo $doc->saveXML();
$doc->save("write.xml")
0

精彩评论

暂无评论...
验证码 换一张
取 消