I need a one liner that trims PHP from an HTML file. The trick is that I also need it to preserve the newlines previously taken up by the PHP lines.
php -r "echo preg_replace('/<\\\\?.*(\\\\?>|\$)/Us','', file_get_contents(\$argv[1]));" -- "./index.php"
This "works" but does not preserve the new lines, for example:
<html><?php test(); ?>
<head>
<?php test();
?>
</head>
<body>
</body>
<html>
Resolves to:
<html>
<head>
</head>
<body>
</body>
<html>
But I need it to resolve to:
<html>
<head>
</head>
<body>
</body>
<html>
Maybe I am using a hammer to drive a screw but what I am trying to do is remove the PHP code, run the result through htmlhint and have the reported line numbers actually match the lines in the file.
If there is a better solution, I would love to hear it. The end goal is to lint files that have a mix of PHP, Javascript and HTML with their respective linters.