A trivial regex that works unless >
characters might occur somewhere within the <body>
tag itself:
Search for <body[^>]*>
and replace the match with $0<mynewtag>
:
$result = preg_replace('/<body[^>]*>/', '$0<mynewtag>', $subject);
Test it live on regex101.com.
0
solved Add html after variable