Let $K$ be the Cantor set. For any $a, b\in \mathbb R,$ $a\ne 0,$ I'll also call $aK+b$ a Cantor set. Since $K$ has the cardinality of $\mathbb R,$ so do these other Cantor sets.
Note that if $U$ is any nonempty open subset of $\mathbb R,$ there exists a Cantor set inside of $U.$
Let $I_1,I_2, \dots$ be the open intervals in $\mathbb R$ with rational end points.
Claim: There are pairwise disjoint Cantor sets $K_1,K_2, \dots$ such that for each $n,$ $K_n \subset I_n.$
The claim is a nice exercise. Let's assume the result. For each $n$ there exists a bijection $f_n:K_n \to \mathbb R.$ Define $f:\mathbb R \to \mathbb R$ as follows. For each $n,$ set $f= f_n$ on $K_n.$ Set $f=0$ everywhere else.
Then $f$ has the desired property. Proof: Suppose $I$ is a nonempty open interval. Then $I_n\subset I$ for some $n.$ Since $K_n \subset I_n,$ we have $\mathbb R = f(K_n) \subset f(I_n) \subset f(I),$ and we're done.