We introduce the concept of a connected logic (over S4) and show that each connected logic with the finite model property is the logic of a subalgebra of the closure algebra of all subsets of the real line R, thus generalizing the McKinsey-Tarski theorem. As a consequence, we obtain that each intermediate logic with the finite model property is the logic of a subalgebra of the Heyting algebra of all open subsets of R.