Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 细枝,将变量与字符串进行比较_Php_String_Twig - Fatal编程技术网

Php 细枝,将变量与字符串进行比较

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

当我需要将变量与字符串进行比较时,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_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);