before vs earlier

  1. I have said it before.
    1a. I have said it earlier.
  2. I didn’t know that. You should have told me before.
    2a. I didn’t know that. You should have told me earlier.
    Which are the sentences correct?

All of them are possible. You would use ‘before’ in some contexts and ‘later’ in others, but there are some contexts which can take either.

Beeesneees,

  1. I wrote a letter before you arrive.
  2. I wrote a letter earlier than you arrive.
    Are these sentences OK?

No

I wrote a letter before you arrived.
I wrote a letter earlier.