By using this code, how do i also remove or str_replace the domain in the resulting $first_img url.

I understand the following function can be included to make this happen:

$url = str_replace(get_bloginfo('url'), '', $url);

Put into the next snippet:

//grab the first post image
function get_the_first_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}