Wolfsoap Posted January 22, 2008 Share Posted January 22, 2008 Hay, I've been looking hard and can't find anything that does this, its pretty strange too. It seems like something that would be commonly used. I want to back up my Blogger blog to a mysql database so i can move all of my posts over to my new site which isn't blogger hosted, but I cant find any way to save all the blogger post to a database. Can anyone help, can anyone save me from the peril of copy and pasting 100's of old blog entires into a new database? Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 capture webcode into variable parse variable using a seperator into an array foreach element in array, insert into db Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 what is your blog url? can you configure it to display ALL posts on one page? Quote Link to comment Share on other sites More sharing options...
Wolfsoap Posted January 22, 2008 Author Share Posted January 22, 2008 its http://wolfsoap.blogspot.com/ i dont have a clue how to "capture webcode into variable parse variable using a seperator into an array foreach element in array, insert into db" Quote Link to comment Share on other sites More sharing options...
Wolfsoap Posted January 22, 2008 Author Share Posted January 22, 2008 if someone wrote some universal code to do that from blogger it would be very popular. there 100's of people with this problem and blogger Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 I'm working on it. here's what I have so far. its ugly. $capture=file_get_contents ('http://resago.blogspot.com'); preg_match('/<div class=\'main section\' id=\'main\'>(.+)<div id=\'sidebar-wrapper\'>/s', $capture, $info); #print_r ($info); $posts="$info[1]"; $posts_array=preg_split('/<a name=\'\d+\'><\/a>/',$posts); #array_shift($posts_array); $posts_array=str_replace('<br />',"\n",$posts_array); $posts_array=preg_replace("/(<\/?)(\w+)([^>]*>)/","",$posts_array); $posts_array=preg_replace("/\n+/","\n",$posts_array); print "<hr><pre>"; print_r($posts_array); Quote Link to comment Share on other sites More sharing options...
Wolfsoap Posted January 22, 2008 Author Share Posted January 22, 2008 im a noob to all this, ive coded my tagtastic blog and thats about it. that all looks cool though. Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 umm, then how are you going to import the posts? ??? Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 I'll make it write out a csv file, the rest is up to you. Quote Link to comment Share on other sites More sharing options...
resago Posted January 22, 2008 Share Posted January 22, 2008 this writes out a text file where each line is a separate post. manipulate in excel however you want, then use simple import. <?php #Look at your blog html code and figure out the following: #These default settings work for the simple blue template on blogspot $blogurl="http://YOU.blogspot.com";#url $begin="<div class=\'main section\' id=\'main\'>";#some unique text to specify starting point $end="<div id=\'sidebar-wrapper\'>";#some unique text to specify ending point $sep="<div class=\'post hentry\'>";#some unique text to specify post separation $keepimages="yes";#change if you don't care about image url ################################################################################# $capture=file_get_contents ($blogurl); preg_match("/$begin(.+)$end/s", $capture, $info);#just get what we need $posts="$info[1]"; $posts_array=preg_split("/$sep/",$posts);#separate posts into array $posts_array=str_replace('<br />',"\n",$posts_array);#turn br into newline if ($keepimages=="yes"){ $posts_array=preg_replace("/<img .*src=\"(.*)\" *\/>/","[img=$1]",$posts_array);# get img src } $posts_array=preg_replace("/(<\/?)(\w+)([^>]*>)/","",$posts_array);# get rid of all tags $posts_array=preg_replace("/\n+/","<br>",$posts_array);#turn newlines back into br $f=fopen("blog.txt","w"); fwrite($f,implode("\n",$posts_array)); fclose($f); # file is saved as a txt file. each line is a post. Manipulate in excel as required. print "<a href='blog.txt'>Download this</a>"; #CLOSE ENOUGH!!! ?> Quote Link to comment Share on other sites More sharing options...
Wolfsoap Posted January 23, 2008 Author Share Posted January 23, 2008 it didnt work i got: Notice: Undefined index: 1 in /path to php file/capture.php on line 13 Quote Link to comment Share on other sites More sharing options...
resago Posted January 23, 2008 Share Posted January 23, 2008 works for me. http://resago.com/blog/blogbackup.php your start and end text is probably wrong. you could set you template to the same I use, then it would work without modification. resago.blogspot.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.