I know little about legal subject matters, and am seeking advice on what an author is allowed to do without getting a lawsuit thicker than the book in question.

Can I, without authorization, write a book that quotes an established fictional character, say "The sayings of Tony Soprano" or the like? My gut feeling tells me no, but then I find books like "Ultimate Unofficial Guide to the Mysteries of Harry Potter" and "The Encyclopedia of Animated Cartoons". The former of the two claims to be unofficial - is it possible to use the name Harry Potter on the front cover without authorization? The latter of the two books seems to be a quite extensive encyclopedia of cartoons - could the authors have gotten permission from all of the license holders?

I am aware of the fact that laws differ from country to country, but any help is much appreciated.