首頁  >  文章  >  後端開發  >  smarty - 請問這段php的錯誤在哪?我沒找到錯啊

smarty - 請問這段php的錯誤在哪?我沒找到錯啊

WBOY
WBOY原創
2016-09-05 08:59:571452瀏覽

這是在網路上找的smarty設定的段碼。

一開始提示
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in F:phpstudyWWWsmartysconfig.php on line 2
我看到第二行沒問題啊,於是自己從新敲了一遍,一抹一樣的,就好了。

然後提示
Parse error: syntax error, unexpected T_VARIABLE in F:phpstudyWWWsmartysconfig.php on line 4
這就很費解了,$tpl = new Smarty(); 這句話有錯嗎?

謝謝。

<code><?php  
  include "/smarty/libs/Smarty.class.php";  
  define(@#__SITE_ROOT@#, @#f:/phpstudy/WWW/smartys/smarty@#); // 最后没有斜线  
  $tpl = new Smarty();  
  $tpl->template_dir = __SITE_ROOT . "/templates/";  
  $tpl->compile_dir = __SITE_ROOT . "/templates_c/";  
  $tpl->config_dir = __SITE_ROOT . "/configs/";  
  $tpl->cache_dir = __SITE_ROOT . "/cache/";  
  $tpl->left_delimiter = @#<{@#;  
  $tpl->right_delimiter = @#}>@#;  
  ?></code>

回覆內容:

這是在網路上找的smarty設定的段碼。

一開始提示
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in F:phpstudyWWWsmartysconfig.php on line 2
我看到第二行沒問題啊,於是自己從新敲了一遍,一抹一樣的,就好了。

然後提示
Parse error: syntax error, unexpected T_VARIABLE in F:phpstudyWWWsmartysconfig.php on line 4
這就很費解了,$tpl = new Smarty(); 這句話有錯嗎?

謝謝。

<code><?php  
  include "/smarty/libs/Smarty.class.php";  
  define(@#__SITE_ROOT@#, @#f:/phpstudy/WWW/smartys/smarty@#); // 最后没有斜线  
  $tpl = new Smarty();  
  $tpl->template_dir = __SITE_ROOT . "/templates/";  
  $tpl->compile_dir = __SITE_ROOT . "/templates_c/";  
  $tpl->config_dir = __SITE_ROOT . "/configs/";  
  $tpl->cache_dir = __SITE_ROOT . "/cache/";  
  $tpl->left_delimiter = @#<{@#;  
  $tpl->right_delimiter = @#}>@#;  
  ?></code>

確保引用路徑正確,或把smarty括號去掉試試看。例如

<code>$tpl = new Smarty;</code>

第一行引入的路徑不對?

像是路徑問題?把路徑最開始的斜線去掉試試看。 。
第一個報錯像是BOM問題吧,別用記事本保存。

@#是什麼,難道是我的顯示有問題?
另外很多人說是引入路徑的問題,顯然這是不對的,錯誤出現在程式碼解釋期,還沒到執行呢。

@#是個什麼鬼?看錯誤訊息,你這不是 new Smarty; 出錯,也不是include出錯。

你是不是網路複製程式碼 我估計是中文字元導致解析錯誤 肉眼無法看出

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn