Escaping a literal <?php and <? in a PHP script
escaping, php
Solution
This:
<?php echo "<?php"; ?>
Will output:
<?php
Problem
I am templatizing my php.ini using PHP. I have a script to set up a development environment by generating httpd.conf, apachectl, and php.ini from templates using a CLI PHP script. Unfortunately there are literal `<?` and `<?php` strings in php.ini (in a comment). Is it possible to escape those somehow so php doesn't interpret them as normal PHP escape sequences? Currently my workaround is to wrap them in a real PHP escape sequence that outputs them as a string, like this: ``` ; This directive determines whether or not PHP will recognize code between ; <?php echo "<? and ?>" ?> tags as PHP source which should be processed as such. It's been ; recommended for several years that you not use the short tag "short cut" and ; instead to use the full <?php echo "<?php and ?>" ?> tag combination. With the wide spread use ; ```