How to Import Xanga into WordPress.com

18 Jun

NOTE: This article is now nearly 2 years old. WordPress has moved on significantly since then, as have some of the other tools employed (such as XAMPP). In theory the process still works, but the instructions may not be exact anymore.

I told a friend that I would help her move all her old Xanga posts to her new WordPress.com account.  Little did I know how much of a difficulty that would be.  After extensive searching via Google, I finally found what I believe to be the best way.  For the benefit of those coming after me, blow-by-blow instructions are below.

Before I begin, you may want to look at Tim Wylie’s Xanga to WordPress Exporter.  I could not get this to work on my friend’s blog, but it did work on a few random strangers’ blogs that I tried.  Please let me know if you get this to work.

Now, on to my method.  This is a bit complicated (ok, it’s really complicated), but I’ve tried to lay out everything clearly.  The problem is that WordPress.com doesn’t let us import from Xanga directly so we have to install WordPress locally, import our Xanga archives, then export to a WordPress file and upload it to WordPress.com.  So here we go:

  1. Upgrade your Xanga account to premium at https://register.xanga.com/premium/. This costs $4 for a one month subscription (make sure to uncheck the “Automatically rebill me!” box) and it’s worth it for all the time you’re going to save.  Just take my word on that and do it.
  2. Go to http://www.xanga.com/private/Archives.aspx and get your Xanga Archives.  If this is your first time getting your archives you may have to wait overnight for Xanga to prepare them. Once you’ve downloaded them, unzip the “archive.zip” file to your desktop.  You should now have a folder called “archive” on your desktop.  Inside that is a folder called “xanga” and inside that are HTML files for each month of posts on Xanga.
  3. Open a command prompt window by going to the Start Menu -> Run and typing in “cmd” and clicking “OK”.  You should see a black window open up that says something along the lines of: “C:\Documents and Settings\Username\”.
  4. Move into your Xanga folder by typing “cd Desktop\archive\xanga” and pressing the enter key.
  5. Now combine all of the Xanga archive files by typing “copy *.htm XangaArchive.htm” and pressing the enter key.  (You can now close the command prompt by typing “exit” and pressing enter.)
  6. Download XAMPP, a wonderful Apache, MySQL, PHP (if you don’t know what these are, don’t worry) installer for Windows athttp://www.apachefriends.org/en/xampp-windows.html#641.  Choose the “Installer” option when you go to download.
  7. When it’s downloaded, run the installer and choose the default options.  This will install XAMPP into the C: drive of your computer.  When the installation finishes click “Yes” when it asks you if you want to run the Control Panel.
  8. Go to the folder C:\xampp\htdocs\php\ (you can navigate there by going to “My Computer”, selecting the “C:” drive and then browsing to the “xampp\htdocs\php\” folder).  Open the file “php5.ini”; it should open in Notepad by default.
  9. Go to Edit -> Find and type in “max_execution_time”.  Change the value from “60″ to “600″ and save the file.  Close Notepad.
  10. On the XAMPP Control Panel, click the “Start” buttons beside “Apache” and “MySql”.   If they start correctly a little green box that says “Running” will appear beside each.  If you are asked to unblock them by the Windows Firewall, do so.
  11. Assuming you are allowed to start both of them, try going to http://localhost/ in your web browser.  If a page saying “XAMPP” loads then you’re good to continue.
  12. Download WordPress 2.5 from http://www.wordpress.org/download/.  When it is downloaded, extract the ZIP file to your Destkop.  This will create a folder on your desktop called something like “wordpress-2.5.1″ and inside that will be another folder called “wordpress”.  Move the second folder (the one just called “wordpress”) into C:\xampp\htdocs\.  (Do this by opening a new “My Computer” window, selecting the “C:” drive and then the browsing to the xampp\htdocs folder.  Drag the “wordpress” folder into it.)
  13. Now go into the “wordpress” folder and click on the “wp-config-sample.php” file.  When it tells you that it cannot open the file, choose “Select the program from a list” and click “OK”.  Scroll down and choose “WordPad” and click “OK”.
  14. At the very top of this file you will see something that looks like this

    define(‘DB_NAME’, ‘putyourdbnamehere’);    // The name of the database
    define(‘DB_USER’, ‘usernamehere’);     // Your MySQL username
    define(‘DB_PASSWORD’, ‘yourpasswordhere’); // …and password

    Change this to look like this:

    define(‘DB_NAME’, ‘wordpress’); // The name of the database
    define(‘DB_USER’, ‘root’); // Your MySQL username
    define(‘DB_PASSWORD’, ”); // …and password

    As you can see, you are changing “putyourdbnamehere” to “wordpress”, changing “usernamehere” to “root”, and changing “yourpasswordhere” to be blank.

  15. Choose File -> Save As in the menu and save the file as “wp-config.php” in the same directory as “wp-config-sample.php”.
  16. Download phpMyAdmin from http://www.phpmyadmin.net/home_page/downloads.php. Choose the “all-languages-utf-8-only.zip” option.
  17. Once it has downloaded, you will have a file named something like “phpMyAdmin-2.11.7-rc1-all-languages-utf-8-only.zip”.  Extract that to your desktop and it will create a folder called “phpMyAdmin-2.11.7-rc1-all-languages-utf-8-only” with another folder of the same name inside of that.  Right click on that inner folder and choose “Rename”.  Then rename the folder to “phpmyadmin” and move it into the C:\xampp\htdocs\ folder just like we moved the “wordpress” folder there.
  18. Now use your web browser to go to http://localhost/phpmyadmin/.  If that page loads, we are good to continue.
  19. Look for the “Create new database” option.  Fill in “wordpress” in the box and click “Create.”  It should tell you that “Database wordpress has been created.”  If so, continue.
  20. Go to http://localhost/wordpress/. We are now at the WordPress installer.
  21. Give your blog a title like “My Xanga” and fill in your email address.  Click “Install WordPress”.
  22. On the next page right down the username and password that it gives you.  Then click “Log In” and log into your WordPress.  Leave this window open and we will come back to it.
  23. Now we need to download the Xanga importer for WordPress.  The original importer comes from Daniel Kozlowski, but I had to modify it to make comments come in correctly.  You can use either version. See update at end of post for the PHP code.
  24. Go back to your WordPress web browser window.  Click on “Manage”.
  25. Select the one post on that page (entitled “Hello world!”) and delete it.  Then click on “Import”.
  26. Choose “Xanga” (all the way at the bottom).
  27. Click “Browse…” and browse to the “XangaArchive.htm” file we created in step 5.  Select it and click “Open”.  Then click “Upload file and import”.  This may take a while.
  28. When that page is done loading scroll all the way to the bottom and see if it says “All done.”  If so, it worked, scroll back to the top and click on “Export”.  Then select “Download Export File” and save the XML file it gives you.
  29. Now go to your WordPress.com account and log in.  Then click on “Manage” and on “Import”.  Choose “WordPress”.
  30. Browse to your WordPress XML file that you just saved and select it.  Click “Upload file and import”.
  31. After it uploads, tell it what author to map your import author to.  Click “Import”.  There you go, you imported Xanga into WordPress.
  32. Go back to the XAMPP Control Panel and click “Stop” beside “Apache” and “MySql”.  Then click “Exit”. Now you can go to “Add or Remove Programs” in the Control Panel and remove XAMPP.
  33. You can also delete all the files you downloaded, though you may want to keep the Xanga archives around just in case.

You’re done! That wasn’t so bad, was it?  Actually, I’ll admit, there are a bunch of places in there that you can get confused.  Feel free to contact me at jim@smidg.in or leave a comment if you need help.

Update: Here is the code for the Xanga importer.  To install it:

  • Navigate to the C:\xampp\htdocs\wordpress\wp-admin\import folder on your computer.
  • Copy one of the files already there and rename it xanga.php. (If you can’t see the “.php” at the end of the file, just rename it “xanga”.)
  • Right click on the file and go to “Open With.” If Wordpad is not in the list, choose to see more programs and select it from that list.
  • Replace all the text in that file with the code below. Save it. Now continue with Step 24.

< ?php

//Xanga archive importer by Jeremy Jay
//Borrows heavily from the LiveJournal import script.
//
//Modified for current WP (2.1+) release and for current Xanga archive style by Daniel Kozlowski
//
//ATTN:  unhtmlentities() has been disabled due to it's turning all ". " into ".? "
//       once the post was imported into wordpress 2.1.  Thus, it has been disabled.  If
//       you're using a version of PHP earlier than 4.3, you'll need to un-comment
//       calls to unhtmlentities() in this script.  They are on lines 82 and 120.
//
//ATTN:  I've run into some Xanga archives where the timestamp for a post or comment is
//	    missing a zero.  For example, "12:08" is printed as "12:8".  This script
//	    cannot read those!  Please read through your code if some of the times are
//       coming up weird once you've imported the archive files.

class Xanga_Import {

    var $file;

    function header() {
        echo '
<div>';
        echo '
<h2>'.__('Import Xanga').'</h2>
';
    }

    function footer() {
        echo '
';
    }

    function unhtmlentities($string) { // From php.net for < 4.3 compatability
        $trans_tbl = get_html_translation_table(HTML_ENTITIES);
        $trans_tbl = array_flip($trans_tbl);
        return strtr($string, $trans_tbl);
    }

    function greet() {
        echo '
'.__('Howdy! This importer allows you to extract posts and comments from Xanga Premium Archive files into your blog.  If you do not have Premium but have enough posts to be looking at this, just pay $4 for a month to get the archive and you will at least be supporting Xanga for all the hosting they have done for you.  Pick an archive file to upload and click Import.').'
';
        wp_import_upload_form("admin.php?import=xanga&step=1");
    }

    function import_posts() {
        global $wpdb, $current_user;

        set_magic_quotes_runtime(0);
        $importdata = file($this->file); // Read the file into an array
        $importdata = implode('', $importdata); // squish it
        $importdata = str_replace(array ("\r\n", "\r"), "\n", $importdata);

        preg_match_all('|
<div>(.*?)<hr size=1 noshade/>(
<div>)*?|is', $importdata, $posts);
        $posts = $posts[1];
        unset($importdata);
        echo '
<ol>';

        foreach ($posts as $post) {
            flush();
            preg_match('|^(.*?)</ol>
</div>
|is', $post, $post_title);
            $post_title = $wpdb->escape(trim($post_title[1]));

            preg_match('/
<div>Posted (.*?)\/(.*?)\/(.*?) at (.*?) (.*?)< \/div>/is', $post, $match);
            list($hour,$min) = explode(':',$match[4]);
            switch($match[5]) {
            	case 'AM' : if($hour == 12) $hour = 0; break;
            	case 'PM': if($hour < 12) $hour += 12; break;
            	}
            $match[4] = "$hour:$min";
            $post_date = "$match[3]-$match[1]-$match[2] $match[4]:00";
            echo "Date: $post_date";

            $com = split(' ', $post_title);

            if( $com[1]=='Comments' ) {
                preg_match_all('|
<div>
<div>(.*?)</div>
</div>
|is', $post, $comments);
                $comments = $comments[1];

                $comment_post_ID = $post_id;
                $num_comments = 0;
                foreach ($comments as $comment) {
                    preg_match('|^(.*?)</div>
<div>|is', $comment, $comment_content);
                    $comment_content = str_replace(array ('< ![CDATA[', ']]>'), '', trim($comment_content[1]));
                    //$comment_content = $this->unhtmlentities($comment_content);

                    // Clean up content
                    $comment_content = preg_replace('|< (/?[A-Z]+)|e', "'<' . strtolower('$1')", $comment_content);
                    $comment_content = str_replace('
', '
', $comment_content);
                    $comment_content = str_replace('<hr>', '<hr />', $comment_content);
                    $comment_content = $wpdb->escape($comment_content);

                    preg_match('/
<div>Posted (.*?)\/(.*?)\/(.*?) at (.*?) (.*?) by/i', $comment, $match);
                    list($hour,$min) = explode(':',$match[4]);
            		switch($match[5]) {
            		case 'AM' : if($hour == 12) $hour = 0; break;
            		case 'PM': if($hour < 12) $hour += 12; break;
            			}
          	  	$match[4] = "$hour:$min";
            	     $comment_date = "$match[3]-$match[1]-$match[2] $match[4]:00";

                  if (preg_match('|<a href="http://www\.xanga\.com/home\.aspx\?user=|', $comment) == 1)
			{
				preg_match('|<a href="http://www\.xanga\.com/home\.aspx\?user=(.*?)">(.*?)|i', $comment, $comment_author);
			}
			else
			{
				preg_match('|<a href="http://www\.xanga\.com/(.*?)">(.*?)</a>|i', $comment, $comment_author);
			}

                    $comment_author = $wpdb->escape(trim($comment_author[1]));
                    $comment_author_url = 'http://www.xanga.com/home.aspx?user='.$comment_author;

                    $comment_approved = 1;
                    // Check if it's already there
                    if (!comment_exists($comment_author, $comment_date)) {
                        $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_date', 'comment_content', 'comment_approved');
                        $commentdata = wp_filter_comment($commentdata);
                        wp_insert_comment($commentdata);
                        $num_comments++;
                    }
                }
                if ( $num_comments ) {
                    echo ' ';
                    printf(__('(%s comments)'), $num_comments);
                }
            } else {

                preg_match('|
<td style="padding-left:20; padding-bottom:20">(.*?)
<div>Posted (\d{1,2}/\d{1,2}/\d{4}) at (.*?)< \/div>|is', $post, $post_content);
                $post_content = str_replace(array ('< ![CDATA[', ']]>'), '', trim($post_content[1]));
                //$post_content = $this->unhtmlentities($post_content);

                // Clean up content
                $post_content = preg_replace('|< (/?[A-Z]+)|e', "'<' . strtolower('$1')", $post_content);
                $post_content = str_replace('
', '
', $post_content);
                $post_content = str_replace('<hr>', '<hr />', $post_content);

                //Xanga archives have some pretty crappy formatting, so this reduces the string to a single line.
                //THIS WILL NOT REMOVE YOUR OWN FORMATTING.  Any formatting changes you created in your posts
                //are tagged, and thus will not be affected by the removal.
                $post_content = str_replace("\n", " ", $post_content);
                $post_content = $wpdb->escape($post_content);

                $post_author = $current_user->ID;
                $post_status = 'publish';

                echo '
	<li>';
                if ($post_id = post_exists($post_title, $post_content, $post_date)) {
                    printf(__('Post <i>%s</i> already exists.'), stripslashes($post_title));
                } else {
                    printf(__('Importing post <i>%s</i>...'), stripslashes($post_title));
                    $postdata = compact('post_author', 'post_date', 'post_content', 'post_title', 'post_status');
                    $post_id = wp_insert_post($postdata);
                    if (!$post_id) {
                        _e("Couldn't get post ID");
                        echo '</li>
';
                        break;
                    }
                }
            }

            echo '
';
            flush();
            ob_flush();
        }
        echo '
';
    }

    function import() {
        $file = wp_import_handle_upload();
        if ( isset($file['error']) ) {
            echo $file['error'];
            return;
        }

        $this->file = $file['file'];
        $this->import_posts();
        wp_import_cleanup($file['id']);

        echo '
<h3>';
        printf(__('All done. <a href="%s">Have fun!</a>'), get_option('home'));
        echo '</h3>
';
    }

    function dispatch() {
        if (empty ($_GET['step']))
            $step = 0;
        else
            $step = (int) $_GET['step'];

        $this->header();

        switch ($step) {
            case 0 :
                $this->greet();
                break;
            case 1 :
                $this->import();
                break;
        }

        $this->footer();
    }

    function Xanga_Import() {
        // Nothing.
    }
}

$xanga_import = new Xanga_Import();

register_importer('xanga', 'Xanga', __('Import posts from Xanga Archives'), array ($xanga_import, 'dispatch'));
?>

Advertisement

Tags: , ,

29 Responses to “How to Import Xanga into WordPress.com”

  1. abbi 19 June 2008 at 10:16 #

    You’re brilliant, you know. And also for your information, I’ve changed my passwords again. ;-b

  2. Hani Salem 20 June 2008 at 21:26 #

    Hi
    you have a nice work here friend
    Thank you to manage the site on topics

  3. christian boas 21 June 2008 at 05:39 #

    WE are Almo Computer in Spain based in Moraira and Altea. We are looking for people whom we can work together with
    and share our expertise with. We are expanding into web design and Seo and looking for people
    who want that service or whom we can outsource the work too.

    please visit our site

    http://www.almocomputer.com

    and contact us if you are interested

  4. tabin 7 July 2008 at 01:32 #

    You are a life-saver. This actually makes my life easier since I already had XMAPP on my computer.

  5. JZ 19 August 2008 at 05:30 #

    Do you know how to import xanga onto blogger.com? I’d be ETERNALLY grateful if you could tell me.

  6. Jim 19 August 2008 at 14:24 #

    @JZ: Unfortunately not. I’d recommend a lot of Google searching, that’s what it took to figure this out. Also, consider more than just moving straight from one to the other. Maybe you can move from Xanga to WordPress (or some other sytem) and from their to Blogger. Good luck!

  7. JZ 28 August 2008 at 17:40 #

    it’s okay, thanks a lot anyway, this was soooo helpful

  8. Sarah 14 September 2008 at 14:12 #

    I am planning on taking a stab at this today — but my end goal is to go xanga to wordpress to typepad. What do you think?

  9. OLC 28 September 2008 at 22:46 #

    Hey, I’m here to let people know that Jim generously took time out of his weekend to help move my column over from another blog site when I had no clue what I was doing (I’m a writer, not a tech guru).

    To say that he helped me would be an understatement. Without him I’d be copying and pasting 4 years worth of writing into my new blog. Luckily for people like me, there are people like Jim out there who are genuinely nice and helpful. (so there’s hope for the world, after all, lol)

    Thank you so much for being sympathetic to my pleas, I’m eternally grateful. People, you can trust this guy, he is a rockstar.

    Thanks Jim!! :D

    OLC

  10. SC 27 November 2008 at 01:05 #

    I tried this tonight and it worked well! Only confusing part was that the xampp link (…#641 on the page) is actually linked to (…#646 – a lite add-on). I used the xampp basic version and it has some of the folders in different places than listed here. It took a little looking to find php5.ini file. Also, no need to download phpmyadmin separately, because it looks like the basic xampp includes it!

    Other than that small thing, it is super-easy to use, and I’ve got my blog free from xanga! :)

  11. Paul Retherford 31 December 2008 at 10:09 #

    Thank you for the useful information. You are a wizard!:-)

  12. Tim Wylie 3 January 2009 at 01:21 #

    Hey, thanks for the link. This is really good information. I was too cheap to pay the $4 back when I switched. Xanga occasionally has slightly different tag formats which messes up my script. I just added another version on my site and a few more directions. (You actually have to run the script though, I didn’t rebuild the GUI). Not that you need it anymore since you’ve converted your site, but I thought I’d mention it if anyone was curious.

  13. Lue-Yee Tsang 9 January 2009 at 12:34 #

    If I ever decide to move my Xanga stuff, thisll be immensely helpful.

  14. Mike 24 February 2009 at 13:31 #

    Hey Jim, just wondering if it would be possible for you to e-mail me the xanga.zip file you had. The link you had up no longer works. If you no longer have the file, that’s no problem, just figured I’d ask.
    Thanks,
    Mike

  15. saharial 18 April 2009 at 06:51 #

    Thanks so much for this! I love learning new bits of coding etc and its made things so much easier!

    the latest version though has changed this:

    xampp\htdocs\php\ folder). Open the file php5.ini

    to

    xampp\php\php.ini

    and it should be
    http://localhost/wordpress/wp-admin/install.php

    also, it might be better to have a direct link to the xanga php
    http://core.trac.wordpress.org/raw-attachment/ticket/2665/xanga_LATEST.php

    in case you feel like updating :)

    thanks so much :)

  16. Mingyi 21 April 2009 at 11:35 #

    Hi there, I tried emailing you but it got rebounded. Will it be possible if you could assist to convert my xanga html files to wordpress format?

  17. iamalwayschanging 19 July 2009 at 19:49 #

    Thanks so much for the instructions! I have been wanting to switch for a long time and you helped me do what I had thought impossible.

  18. yieny 23 September 2009 at 04:38 #

    hai. I need your help. Seriously. I want to import all my xanga enteries to blogger. But I dont know how to get my xanga achieves file. How? Help me please!!!

  19. Josh 5 January 2010 at 16:53 #

    Thank you so much!

  20. ahnia 17 February 2010 at 10:02 #

    Hi Jim,

    I’m trying to move my xanga blog to wordpress. I have an XML which I managed to import from Xanga but can’t seem to upload it onto wordpress. Would I need to convert it to a wordpress file? Are you able to help me out? It’s so confusing..

    Thanks!

    • Jim 17 February 2010 at 13:25 #

      Have you gone through the process described above? If you have, your XML file should import into WordPress. If not, some conversion still needs to happen. What step are you at?

  21. ahnia 22 February 2010 at 08:44 #

    I didn’t get premium Xanga to get my XML file. There was a post on a forum teaching you to get the XML which was used notepad and a brower. Would I be able to use that or would I need to follow your method above? I’m quite confused as I don’t understand any html :(

    • Jim 23 February 2010 at 02:54 #

      I don’t know if you’ll be able to use it. You need an XML file in a Xanga export format. If this other process gets you that, you’re good to go. You could open the two files in Notepad and compare them.

  22. Marisela 3 September 2010 at 19:14 #

    I’ve been contemplating a move to WP from Xanga for a while. Since this is an old post, do you still advise these directions? I’m only a little versed in html code, this is a little daunting. But thanks for all the info.

    • Jim 3 September 2010 at 19:23 #

      In theory the principle still works. I haven’t tried it myself recently, so I’m sure there are parts that are changed. And there may be a better way by now too.

  23. h3Artily 11 January 2011 at 04:45 #

    hey!
    Thanks so much for the step by step “TO DO LIST” for porting Xanga entries to WP.

    However, I am currently stuck at step 20. The page loads with “Error establishing a database connection”. Currently using “wordpress-3.0.4″ & “phpMyAdmin-3.3.9-all-languages” instead. All directions work up to that step. Any advice? =)

  24. maisyyau 16 June 2011 at 08:39 #

    a little green box that says “Running” will appear beside “MySql”.

    http://localhost/ cannot open!

    How come I find the solutions for 2 days and still cannot import xanga to wordpress or blogger!!

    please help!!

Trackbacks/Pingbacks

  1. this year « naked grass - 31 January 2009

    [...] I found by Googling my problem, I was able to import my Xanga archives with one simple click. Many thanks to you, Jim — I owe [...]

  2. In The Beginning « Through My Looking Glass - 24 March 2009

    [...] Oh, and this man is my hero for now: How to Import Xanga to WordPress [...]

Comments are closed.

Follow

Get every new post delivered to your Inbox.