Writing HTML that contains PHP tags to file
I think what I'm trying to do must be impossible; incredibly difficult; or
pretty easy, and I just don't know how to express what I want correctly to
Google.
What I want to do is the following:
For the purposes of templating, I am outputting HTML to a file. However, I
want the file to contain PHP tags - not the parsed value of the PHP code
(this value will change based upon included scripts in the output file) -
but the actual <?php ?> tags themselves - containing the unmodified code,
such that the code is still executable at run time.
This is an example of what I want to get outputted:
<html>
<body>
<img src="<?php echo IMG_PATH;?>img.jpg" />
</body>
</html>
What I'm getting is a combination of things that are wrong, depending on
which method I use. Basically, I need to be able to write parsable PHP
code to a HTML file. Now, whether or not this is a good idea is debatable,
and a subject I'm not too interested in at the moment. I just want to know
if a sane solution exists.
I came up with the following insane solution:
$content='<html><body><img src="zxzxzx?php echo IMG_PATH; ?qjqjqj" />';
file_put_contents($file,$content);
$command='perl -p -i.bktmp -e "s/zxzxzx/</g" '.$file.' 2>'.$path.'error.log';
$command2='perl -p -i.bktmp -e "s/qjqjqj/>/g" '.$file.'
2>'.$path.'error.log';
exec($command);
exec($command2);
Now, on one hand, this feels devilishly clever. And, it also feels insane.
Is there a better/possible way to do this?
No comments:
Post a Comment