[Solved] Regex to find substring inside an html attribute [duplicate]
My warning in the comments section being said, you could use a combination of preg_replace_callback() and str_replace(): $str=”<input data-content=”This is a text string with a <br /> inside of it” />”; $regex = ‘/data-content=”([^”]*)/i’; $str = preg_replace_callback($regex, function($matches) { return str_replace(array(‘<br/>’, ‘<br />’), ”, $matches[0]); }, $str); echo $str; // output: <input data-content=”This is a … Read more