开发者

how to create site maps from MySQL database?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜