The problem with your syntax on preg_replace() is that you did not define the pattern as an accurate regular expression. Your method would work if you used str_replace(), but for preg_replace(), the correct pattern for identifying <i>
is '/<i>/'
. Basically, you need to enclose it in /
chars to define it as a regex.
Jonathan's expression is much better than a pattern by pattern implementation, if you are looking to remove all tags. If not, you can handle specific tags like this:
$test = "Home<i>\r</i><i>\n</i>";
$patterns = array();
$patterns[0] = '/<\/?i>/'; //removes <i> and </i>
$patterns[1] = '/\r|\n/'; //removes \r and \n
$test = preg_replace($patterns, '', $test);