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

标签 escaping php

我正在使用 PHP 模板化我的 php.ini。我有一个脚本可以通过使用 CLI PHP 脚本从模板生成 httpd.conf、apachectl 和 php.ini 来设置开发环境。不幸的是有文字 <?<?php php.ini 中的字符串(在注释中)。是否有可能以某种方式转义那些以便 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
;

最佳答案

这个:

<?php echo "<?php"; ?>

将输出:

<?php

关于转义文字 <?php 和 <?在 PHP 脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1469105/

相关文章:

python - 在 Jinja2 中渲染时转义双引号

python - 在标记自定义迷你格式时正确考虑多个反斜杠

PHP:如何使用 set_error_handler() 正确处理除通知之外的所有错误?

php - 从帐户中删除所有电子邮件

xslt - 使用 XSLT 取消转义 HTML 实体

javascript - JavaScript 字符串中转义 html 中未终止的字符串文字

mysql - 在 bash 脚本中转义 mysql 引号

php - Bootstrap css 不适用于 codeigniter

php - 在 PHP 中使用 Post 进行 Ajax 调用

php - 在 Wordpress 主题中使用 sidebar.php