Replace html markup in strings

Wednesday, November 4, 2015

How can I replace html elements in strings which have mixed content such as:



$str = "Find the   element in this string";


I'd like to clear all &nbsp ; elements in the string. So, I tried:



str_replace(" ", " ", $str);


I know that &nbsp ; is space and renders as empty space, however there is a specific reason I need to do that related to other DB operations i have.



If str_replace doesn't work for HTML tags, should I use regular expressions?

0 comments:

Post a Comment