Aug 112006




    header(‘Content-type: text/plain’);
    $username = “databaseuser”;
    $password = “password”;
    $dbname = “dbname”;
    $db_con = mysql_connect($hostname,$username, $password) or die(“Connetion to database failed!”);
    mysql_query(“SET NAMES ‘utf8′”);
    $query = “SELECT
    RIGHT OUTER JOIN `wp_posts` ON (`wp_comments`.`comment_post_ID` = `wp_posts`.`ID`)
    LEFT OUTER JOIN `wp_users` ON (`wp_posts`.`post_author` = `wp_users`.`ID`)
    INNER  JOIN  `wp_post2cat`  ON (  `wp_posts`.`ID`  =  `wp_post2cat`.`post_ID`  )
    LEFT  OUTER  JOIN  `wp_categories`  ON (  `wp_categories`.`cat_ID`  =  `wp_post2cat`.`category_ID`  )
    $result = mysql_query($query);
    if ($result) {
        $numOfRows = mysql_num_rows ($result);
        for ($i = 0; $i < $numOfRows; $i++) {
            if ($prev_entry == mysql_result($result, $i, “post_date”)) {
                print_comment($result, $i);
            } else {       
                print_post($result, $i);
                $prev_entry = mysql_result($result, $i, “post_date”);
                if (mysql_result($result, $i, “comment_content”) != “”) {
                    #echo (“—–\n”);
                    print_comment($result, $i);
    mysql_close ();
    function print_post($result, $i) {
        echo (“——–\n”);
            echo (“AUTHOR: “).stripslashes(mysql_result($result, $i, “user_nicename”)).”\n”;
            echo (“TITLE: “).stripslashes(mysql_result($result, $i, “post_title”)).”\n”;
            echo (“STATUS: Publish\n”);
            echo (“ALLOW COMMENTS: 2\n”);
            //echo (“CONVERT BREAKS: markdown\n”);
            echo (“ALLOW PINGS: 0\n”);
            echo (“CATEGORY: “).stripslashes(mysql_result($result, $i, “cat_name”)).”\n”;
            echo (“DATE: “).date(“m/d/Y h:m:s A”,(strtotime(mysql_result($result, $i, “post_date”)))).”\n”;
            echo (“—–\n”);
            echo (“KEYWORDS:\n”);
            echo stripslashes(mysql_result($result, $i, “post_name”)).”\n”;
            echo (“—–\n”);
            echo (“BODY:\n”);
            echo stripslashes(str_replace(“<br />”, “”, mysql_result($result, $i, “post_content”))).”\n”;
            echo (“—–\n”);

    function print_comment($result, $i) {
        $text=stripslashes(str_replace(“<br />”, “”, mysql_result($result, $i, “comment_content”))).”\n”;
        if (0 === strpos($text,’<trackback />’)) {
            preg_match (“!<trackback /><strong>(.+)</strong>\n(.+)!”,$text,$matches);
            echo (“PING:\n”);
            echo (“BLOG NAME: “).stripslashes(mysql_result($result, $i, “comment_author”)).”\n”;
            echo (“URL: “).stripslashes(mysql_result($result, $i, “comment_author_url”)).”\n”;
            echo (“TITLE: $matches[1]\n”);
            $text = “$matches[2]\n”;
        } else {
            echo (“COMMENT:\n”);
            echo (“AUTHOR: “).stripslashes(mysql_result($result, $i, “comment_author”)).”\n”;
            echo (“EMAIL: “).stripslashes(mysql_result($result, $i, “comment_author_email”)).”\n”;
            echo (“URL: “).stripslashes(mysql_result($result, $i, “comment_author_url”)).”\n”;
        echo (“IP: “).stripslashes(mysql_result($result, $i, “comment_author_ip”)).”\n”;
        echo (“DATE: “).date(“m/d/Y h:m:s A”,(strtotime(mysql_result($result, $i, “post_date”)))).”\n”;
        echo $text;
        echo (“—–\n”);






    mysql_query(“SET NAMES ‘utf8′”);


2,可以通过修改function print_post函数中的这些echo语句来控制导出数据的某些参数,比如我的WP中的文章已经用br换行了,所以我注释掉了echo (“CONVERT BREAKS: markdown\n”);这一句来避免出现导出的数据过滤br而无法断行。

  3 Responses to “从WordPress导出数据到Movable Type的方法”

  1. 很好!好文章,谢谢分享!

  2. With the growing number of free-to-play MOBAs entering the
    market and competitor League of Legends having grown into an industry behemoth, it was only
    a matter of time before Ho – N converted to a form of the free-to-play model.
    An intern in a hospital is dispatched to the morgue located in the basement of the building.
    This year’s Lunar Revel reveals three new lively and limited
    time celebratory skins.

    Check out my web site; unturned hack tool

  3. Quality articles is the main to interest the visitors to pay
    a visit the web page, that’s what this website is providing.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>