Hi All Im trying to write a regular expression that takes the HTML of a page in a string and then appends my string just before the </body> tag . This is what i have to append my string after the </body> but i want my string to go before the </body> tag. $mystring = '<b>test</b>'; $_html_body = preg_replace('#\<\s*/body(.*?)\>#si', "$0\n$_mystring" , $_html_body, 1); PHP: Thanks in advance
$_html_body = preg_replace('~</body>~i', "{$mystring}\n{$0}", $_html_body, 1); PHP: Untested but should work.