automated text altering in php?

He has: 688 posts

Joined: Feb 2001

Blogger is kicking out all FTP blogs next month so I (and thousands more) have been switching to self hosted WordPress blogs. I took this switch over as an opportunity to move my blog to a new domain too. All that is done and workding well. Before Blogger cuts me off, I want to replace all my old posts with a link to it's new location, but here's the situation...

My old URLs look like this:
http://www.[firstdomain.com]/blog/[date]/[post-title].php

My new URLs look like this:
http://www.[seconddomain.com]/blog/[date]/[post-title]

Aside from the big change in domain name, you'll notice that my old Blogger URLs ended with ".php" but the new WordPress URLs for all these posts just end with post title name and not the ".php" extension.

In Blogger, I can make it print out the old post's URL. Is there any way via php or something that I can tell it to take that address and "chop off the .php at the end" (or for that matter "chop off the http://www.[firstdomain.com] at the beginning). Can a process like that be easily automated via php, or do I need to look for a different solution?

Thanks.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

This should work:

<?php
$old_url
= 'http://www.firstdomain.com/blog/date/post-title.php';

/**
* Remove the last 4 characters (.php)
*/
$new_url = substr($old_url, 0, -4);

/**
* Replace the old domain name with the new domain name
*/
$new_url = str_replace('firstdomain.com', 'seconddomain.com', $new_url);

echo
$new_url;
?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.