转义文字<?php和<?在PHP脚本中

noh*_*hat 8 php escaping

我正在使用PHP模板化我的php.ini.我有一个脚本来通过使用CLI PHP脚本从模板生成httpd.conf,apachectl和php.ini来设置开发环境.不幸的是php.ini中有文字<?<?php字符串(在评论中).有可能以某种方式逃避这些,所以PHP不会将它们解释为正常的PHP转义序列吗?

目前我的解决方法是将它们包装在一个真正的PHP转义序列中,将它们作为字符串输出,如下所示:

; 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
;
Run Code Online (Sandbox Code Playgroud)

gah*_*ooa 12

这个:

<?php echo "<?php"; ?>
Run Code Online (Sandbox Code Playgroud)

将输出:

<?php
Run Code Online (Sandbox Code Playgroud)

  • 作品。真的没有办法真正逃脱`&lt;?`? (2认同)
  • 不。没办法。 (2认同)