Punctuation and Quotes question

Which is correct - placing the punctuation inside the end quote, or outside?

Example:

“I don’t know which is correct,” said Dooku, “and it has been driving me crazy.”

“I don’t know which is correct”, said Dooku, “and it has been driving me crazy”.

I learned it the first way, but I see it done wrong in printed media all the time…

There are loads of threads about this if you want more opinions, but here’s your answer:

The first example is correct in American English. The second example is correct in British English. There are people who will tell you that the first example is correct in American English too, but they are wrong.

The rules are different for colons, semi-colons, and dashes; or if a quoted phrase contains a question mark or exclamation point.

In American English, you put the period, comma, question mark or exclamation point inside the quotes. This used to be true in Brittish Eglish but they changed it. The one tolerably exception in American English is technical books, where putting a period inside a quoted programming example could cause untold catastrophe.

An addendum to friedo’s answer is that for question marks and exclamation point, they go inside the quotation marks if the quoted part is a question/exclamation. They can go outside if the entire sentence is a question/exclamation, but the quoted portion isn’t.

For “traditional” American English grammar, commas and periods always go inside the quotation marks, though I’ve seen more exceptions to this recently.