<?php $str = "Hello World" ; $regex = '/\n/'; echo preg_replace($regex, ' - ', $str); // returns H$H$H$H$