This work presents a steady-state and time-resolved UV-visible spectroscopic investigation of two antibiotics belonging to the family of tetracyclines (doxycycline and oxytetracycline) in the micellar medium provided by p-dodecyloxybenzyltrimethylammonium bromide (pDoTABr). The spectroscopic analysis has been performed in absorption and emission with femtosecond time resolution, and at pH 5.0 and 8.7 where doxycycline and oxytetracycline are present in their neutral-zwitterionic and monoanionic forms, respectively. The experimental data have been processed by sophisticated data mining methods such as global/target analysis and the maximum entropy method. The results unambiguously indicate that, when doxycycline and oxytetracycline are in their zwitterionic form, they are entrapped within the micelle, while when they are in their monoanionic form, they preferentially show a strong one-to-one interaction with the positively charged surfactant heads. Thus, the pH of the solution controls the inclusion of the investigated drugs into the micelle. When the drugs are entrapped inside the micelles, their spectroscopic and dynamical properties after photoexcitation change appreciably. Interestingly, the entrapped drugs are still able to strongly bind Mg(2+) cations, crucial in determining the biological functioning of tetracyclines. The femtosecond resolved measurements reveal that the drugs are efficiently pulled out of the micelles by Mg(2+). In fact, magnesium-tetracycline complexes are detected in the aqueous phase. The present study suggests the potential promising use of ammonium surfactant micelles embedding doxycycline and oxytetracycline as "smart" drug delivery systems allowing their pH controlled inclusion and Mg(2+) induced release.