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
;
Escape Sequences In PHP, an escape sequence starts with a backslash \ . Escape sequences apply to double-quoted strings. A single-quoted string only uses the escape sequences for a single quote or a backslash.
Escaping is a technique that preserves data as it enters another context. PHP is frequently used as a bridge between disparate data sources, and when you send data to a remote source, it's your responsibility to prepare it properly so that it's not misinterpreted.
Note: PHP statements end with a semicolon ( ; ).
Widely used Escape Sequences in PHP \\ – To escape the backslash. \$ – To escape $. \n – To add line breaks between strings. \t – To add tab space. \r – For carriage return.
This:
<?php echo "<?php"; ?>
Will output:
<?php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With