hankknight
asked on
PHP: Put code after </html> before </body>
Using PHP (and maybe REGEX), I want to move all text after </html> and put it before </body>
<?php
$str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
<script type="text/javascript">
/*<![CDATA[*/
alert('Hi');
/*]]>*/
</script>
';
$str = fixEnding($str);
function fixEnding($str) {
return $str; // Should everything after </html> to before </body>
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If this is yout test.php file, it can be done like this:
<?php
$f = file_get_contents("test.php");
$array = explode('</html>',$f);
$pos = strpos($f,'</body>');
$combine = substr($f,0,$pos).$array[1]."\n</body></html>";
echo"$combine";
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
str=preg_replace('/<\/body