Php 细枝,将变量与字符串进行比较
当我需要将变量与字符串进行比较时,twig中的一个非常简单的模板存在问题 模板Php 细枝,将变量与字符串进行比较,php,string,twig,Php,String,Twig,当我需要将变量与字符串进行比较时,twig中的一个非常简单的模板存在问题 模板 {% if test_var != "" %} Test 42 {% endif %} PHP代码 require_once REP_GLOBAL."/vendor/autoload.php"; $loader = new Twig_Loader_Filesystem(array(REP_GLOBAL."/ressources/twig/emails")); $twig = new Twig_Environme
{% if test_var != "" %}
Test 42
{% endif %}
PHP代码
require_once REP_GLOBAL."/vendor/autoload.php";
$loader = new Twig_Loader_Filesystem(array(REP_GLOBAL."/ressources/twig/emails"));
$twig = new Twig_Environment($loader);
$template = $twig->loadTemplate('maj_coord_perso.html');
$msg = $template->render(array('test_var' => "TEST"));
echo $msg;
错误
PHP Fatal error:
Uncaught exception 'Twig_Error_Syntax' with message 'Unexpected character "\\"
in "maj_coord_perso.html" at line 1' in ***/vendor/twig/twig/lib/Twig/Lexer.php:282\n
Stack trace:\n
#0 ***/vendor/twig/twig/lib/Twig/Lexer.php(203): Twig_Lexer->lexExpression()\n
#1 ***/vendor/twig/twig/lib/Twig/Lexer.php(109): Twig_Lexer->lexBlock()\n
#2 ***/vendor/twig/twig/lib/Twig/Environment.php(469): Twig_Lexer->tokenize('{% if address.w...', 'maj_coord_perso...')\n
#3 ***/vendor/twig/twig/lib/Twig/Environment.php(559): Twig_Environment->tokenize('{% if address.w...', 'maj_coord_perso...')\n
#4 ***/vendor/twig/twig/lib/Twig/Environment.php(331): Twig_Environment->compileSource('{% if address.w...', 'maj_coord_perso...')\n
模板文件的编码是ISO-8859-1,但我在使用UTF-8编码模板时遇到了相同的错误
我缺少什么?我找到了解决方案:
set_magic_quotes_runtime(0);