<?php
$source = '
<body></body>
<body class="foobar"></body>
';
$bodyTag = "foobar";
'/<body([\S\s][^>]*)>/',
'<body$1><noscript>' . $bodyTag . '</noscript>',
$source
);
echo $source;
PD9waHAKCiRzb3VyY2UgPSAnCjxib2R5PjwvYm9keT4KPGJvZHkgY2xhc3M9ImZvb2JhciI+PC9ib2R5PgonOwoKJGJvZHlUYWcgPSAiZm9vYmFyIjsKCiRzb3VyY2UgPSBwcmVnX3JlcGxhY2UoCiAgICAnLzxib2R5KFtcU1xzXVtePl0qKT4vJywKICAgICc8Ym9keSQxPjxub3NjcmlwdD4nIC4gJGJvZHlUYWcgLiAnPC9ub3NjcmlwdD4nLAogICAgJHNvdXJjZQopOwoKZWNobyAkc291cmNlOw==