php中smarty模板中如何使用preg_match_all和preg_replace函数?
如:{$get_all_pic = preg_match_all('/(<img[^>]+alt\s*=\s*"?([^>"\s]+)"?[^>]*[^>]+src\s*=\s*"?([^>"\s]+)"?[^>]*>)/im',$content,$arr_back)}
本地可用,上传服务器后不可用,是不是smarty版本不一样?
案例网址:http://www.xinzaozhuang.com/
Smarty2åSmarty3å¨å®ç°ä¸å·®ä¸å¤ï¼ä½æ¯å¨smarty2å级å°smarty3çæ¶åè¿æ¯è¦æ³¨æäºè®¸ä¸åã
ä¸é¢æ¯å·²ç¥çåsmarty2ä¸å ¼å®¹çå°æ¹ == è¯æ³ ==Smarty 3 APIæäºæ¹é¢è¿è¡äºæ´æ°ãä¸äºSmarty 2 APIè°ç¨éè¦æ´æ°ä»¥ä¾¿ç¬¦åSmarty 3ãä½ å¯è½ä¼å¾å°æ示ï¼æ¨èä½ ä½¿ç¨æ°çè¯æ³ãå¯ä»¥æ¥çSmarty 3é带ç README æ件è·å¾æ´å¤ä¿¡æ¯ã
{$array|@mod} è¯æ³æ»æ¯è®©äººè¿·æï¼å ä¸@符å·è¯´æ修饰符ä½ç¨äºæ°ç»èä¸æ¯ä½ç¨äºæ°ç»çæ¯ä¸ªå ç´ ãéå¸¸ä½ æ»æ¯æ³è®©è¿ä¸ªä¿®é¥°ç¬¦ä½ç¨äºè¿ä¸ªåéèä¸å¿ èèå®çç±»åãå¨ Smarty 3ä¸ï¼{$array|mod} å {$smary|@mod}
æ¯çåçãå»æ@符å·ï¼ä¿®é¥°ç¬¦ä»ç¶ä½ç¨äºæ°ç»ãå¦æä½ æ³ä¿®é¥°ç¬¦ä½ç¨äºæ°æ®å ç´ ï¼ä½ å¿ é¡»å¨æ¨¡æ¿ä¸å¾ªç¯æ°ç»ï¼æè 使ç¨èªå®ä¹ä¿®é¥°ç¬¦ä»¥æ¯ææ°ç»éåã
大å¤smrtyå½æ°å·²ç»å¨éè¦çå°æ¹ä¾å¦{html_options}è¿è¡äºè½¬ä¹ã == PHPçæ¬ ==Smarty 3 ä» æ¯æPHP 5. å¨PHP 4å°ä¸è½æ£å¸¸å·¥ä½ã == {php} æ è®° ==
Smarty 3 é»è®¤å ³é {php} æ è®°æ¯æï¼ä¸æ¨è使ç¨ãä½ å¯ä»¥éè¿è®¾ç½®$smarty->allow_php_tag=trueæ¥å¯ç¨ã{php} åä¸çåéä¸åä¸åä¸é¡µä¸çå ¶å®{php}åå ±äº«ä½ç¨åï¼å æ¤å¨ä½¿ç¨çæ¶åè¦æ³¨æã == å®ç符åç©ºæ ¼ ==
Smarty å®ç符 {} æç©ºæ ¼å å´æ¯ä¸å认为æ¯Smartyæ è®°ãå æ¤ï¼{ foo } å°è¢«Smarty忽ç¥ï¼ä½æ¯ {foo} å°è¢«è¯å«ãè¿ä¸ªååä½¿å¾ Javascript/CSSæ´å®¹æå¨smartyä¸ä½¿ç¨ï¼è没æå¿ è¦ä½¿ç¨ {literal}.
è¿ä¸ªç¹æ§å¯ä»¥éè¿è®¾ç½® $smarty->auto_literal = false; ç¦ç¨ã == æªç¨å¼å·çå符串 ==
Smarty 2 对äºåæ°ä¸æªç¨å¼å·æ¬èµ·æ¥çå符串æç¹å®½å®¹(并ä¸æ¨¡æ£±ä¸¤å¯)ãSmarty 3 æ¯è¾ä¸¥æ ¼ã对äºä¸å å«ç¹æ®å符(A-Za-z0-9_ä¹å¤çå符)çå符串ä»ç¶å¯ä»¥ä¸ç¨å¼å·æ¬èµ·æ¥ãæ¯å¦ä¸é¢ä¾åä¸æ件åå°±å¿ é¡»ç¨å¼å·æ¬èµ·æ¥ã[xhtml]view plaincopy{assign var=foo value=baz} <-- works ok {include file="path/foo.tpl"} <-- needs quotes! == æ©å±Smartyç±» ==
Smarty 3 éµå¾ªPHP5æ åæé è§åãæ©å±Smartyç±»çæ¶åï¼ä½¿ç¨ __construct() ä½ä¸ºç±»çæé å½æ°çå称ãå¦æä½ å®ç°èªå·±çæé å½æ°ï¼ä¸å®è¦å è°ç¨ parent::__construct() [php]view plaincopyclass MySmarty extends Smarty { function __construct() { parent::__construct(); // your initialization code goes here } } == èªå¨å è½½å¨ ==
Smarty ç¨spl_autoload_registerå½æ° å®ç°äºå®èªå·±çèªå¨å è½½å¨ãå¦ææ³å¨èªå·±çåºç¨ä¸ä½¿ç¨èªå¨å è½½å¨ï¼å°±å¿ 须使ç¨æ¤æ¹æ³æ³¨åã
ä½¿ç¨ __autoload() å°å¤±è´¥ã è¿æ¯PHP5æ åèªå¨å è½½å½æ°ãå¯ä»¥æ¥ç
http://us3.php.net/manual/en/function.spl-autoload-register.php== æ件æ件å ==
èªä»Smarty 3使ç¨é»è®¤çsplèªå¨å è½½å¨ï¼å°±è¦æ±æ件æ件å使ç¨å°ååæ¯ãSmarty 2 å 许使ç¨å¤§å°åæ··åæ件åï¼ä½ å¿ é¡»éå½å以ç¨äºsmarty 3. == Smartyç¹æ®åéä½ç¨å ==
å¨Smarty 2ä¸Smartyç¹æ®åé $smarty.section.* and $smarty.foreach.*
æ¥æå ¨å±ä½ç¨åãå¦æå模æ¿ä¸å«æååç循ç¯ï¼å°±ä¼è¦çç¶æ¨¡æ¿ä¸çå¼ãå¨Smarty 3ä¸è¿äºç¹æ®åéå°åªä½ç¨äºå®ä¹å¾ªç¯æå¨ç模æ¿ãè¥æ¯éè¦å¨å模æ¿ä¸ä½¿ç¨ï¼å°±ä¸å¾ä¸ä½¿ç¨åæ°ä¼ éã
<source lang="smarty">
{include file="path/foo.tpl" index=$smarty.section.foo.index}
</source>== SMARTY_RESOURCE_CHAR_SET ==
Smarty 3 设置常é SMARTY_RESOURCE_CHAR_SET 为 utf-8ä½ä¸ºæ¨¡çæ件çé»è®¤å符é.
åªæ¯ä½ä¸ºå escape çå½æ°çé»è®¤å符é. å¦æä½ ç模æ¿ä½¿ç¨å ¶å®å符é, å°±å¿ é¡»èªå·±å®ä¹è¿ä¸ªå¸¸é.== trigger_error()
API å½æ° trigger_error() 已被移é¤ã == Smarty 常é ==
ä¸é¢è¿äºå¸¸é
SMARTY_PHP_PASSTHRU
SMARTY_PHP_QUOTE
SMARTY_PHP_REMOVE
SMARTY_PHP_ALLOW
已被类常éæ¿ä»£
Smarty::PHP_PASSTHRU
Smarty::PHP_QUOTE
Smarty::PHP_REMOVESmarty::PHP_ALLOW追é®
ä¸é¢æ¯å·²ç¥çåsmarty2ä¸å ¼å®¹çå°æ¹ == è¯æ³ ==Smarty 3 APIæäºæ¹é¢è¿è¡äºæ´æ°ãä¸äºSmarty 2 APIè°ç¨éè¦æ´æ°ä»¥ä¾¿ç¬¦åSmarty 3ãä½ å¯è½ä¼å¾å°æ示ï¼æ¨èä½ ä½¿ç¨æ°çè¯æ³ãå¯ä»¥æ¥çSmarty 3é带ç README æ件è·å¾æ´å¤ä¿¡æ¯ã
{$array|@mod} è¯æ³æ»æ¯è®©äººè¿·æï¼å ä¸@符å·è¯´æ修饰符ä½ç¨äºæ°ç»èä¸æ¯ä½ç¨äºæ°ç»çæ¯ä¸ªå ç´ ãéå¸¸ä½ æ»æ¯æ³è®©è¿ä¸ªä¿®é¥°ç¬¦ä½ç¨äºè¿ä¸ªåéèä¸å¿ èèå®çç±»åãå¨ Smarty 3ä¸ï¼{$array|mod} å {$smary|@mod}
æ¯çåçãå»æ@符å·ï¼ä¿®é¥°ç¬¦ä»ç¶ä½ç¨äºæ°ç»ãå¦æä½ æ³ä¿®é¥°ç¬¦ä½ç¨äºæ°æ®å ç´ ï¼ä½ å¿ é¡»å¨æ¨¡æ¿ä¸å¾ªç¯æ°ç»ï¼æè 使ç¨èªå®ä¹ä¿®é¥°ç¬¦ä»¥æ¯ææ°ç»éåã
大å¤smrtyå½æ°å·²ç»å¨éè¦çå°æ¹ä¾å¦{html_options}è¿è¡äºè½¬ä¹ã == PHPçæ¬ ==Smarty 3 ä» æ¯æPHP 5. å¨PHP 4å°ä¸è½æ£å¸¸å·¥ä½ã == {php} æ è®° ==
Smarty 3 é»è®¤å ³é {php} æ è®°æ¯æï¼ä¸æ¨è使ç¨ãä½ å¯ä»¥éè¿è®¾ç½®$smarty->allow_php_tag=trueæ¥å¯ç¨ã{php} åä¸çåéä¸åä¸åä¸é¡µä¸çå ¶å®{php}åå ±äº«ä½ç¨åï¼å æ¤å¨ä½¿ç¨çæ¶åè¦æ³¨æã == å®ç符åç©ºæ ¼ ==
Smarty å®ç符 {} æç©ºæ ¼å å´æ¯ä¸å认为æ¯Smartyæ è®°ãå æ¤ï¼{ foo } å°è¢«Smarty忽ç¥ï¼ä½æ¯ {foo} å°è¢«è¯å«ãè¿ä¸ªååä½¿å¾ Javascript/CSSæ´å®¹æå¨smartyä¸ä½¿ç¨ï¼è没æå¿ è¦ä½¿ç¨ {literal}.
è¿ä¸ªç¹æ§å¯ä»¥éè¿è®¾ç½® $smarty->auto_literal = false; ç¦ç¨ã == æªç¨å¼å·çå符串 ==
Smarty 2 对äºåæ°ä¸æªç¨å¼å·æ¬èµ·æ¥çå符串æç¹å®½å®¹(并ä¸æ¨¡æ£±ä¸¤å¯)ãSmarty 3 æ¯è¾ä¸¥æ ¼ã对äºä¸å å«ç¹æ®å符(A-Za-z0-9_ä¹å¤çå符)çå符串ä»ç¶å¯ä»¥ä¸ç¨å¼å·æ¬èµ·æ¥ãæ¯å¦ä¸é¢ä¾åä¸æ件åå°±å¿ é¡»ç¨å¼å·æ¬èµ·æ¥ã[xhtml]view plaincopy{assign var=foo value=baz} <-- works ok {include file="path/foo.tpl"} <-- needs quotes! == æ©å±Smartyç±» ==
Smarty 3 éµå¾ªPHP5æ åæé è§åãæ©å±Smartyç±»çæ¶åï¼ä½¿ç¨ __construct() ä½ä¸ºç±»çæé å½æ°çå称ãå¦æä½ å®ç°èªå·±çæé å½æ°ï¼ä¸å®è¦å è°ç¨ parent::__construct() [php]view plaincopyclass MySmarty extends Smarty { function __construct() { parent::__construct(); // your initialization code goes here } } == èªå¨å è½½å¨ ==
Smarty ç¨spl_autoload_registerå½æ° å®ç°äºå®èªå·±çèªå¨å è½½å¨ãå¦ææ³å¨èªå·±çåºç¨ä¸ä½¿ç¨èªå¨å è½½å¨ï¼å°±å¿ 须使ç¨æ¤æ¹æ³æ³¨åã
ä½¿ç¨ __autoload() å°å¤±è´¥ã è¿æ¯PHP5æ åèªå¨å è½½å½æ°ãå¯ä»¥æ¥ç
http://us3.php.net/manual/en/function.spl-autoload-register.php== æ件æ件å ==
èªä»Smarty 3使ç¨é»è®¤çsplèªå¨å è½½å¨ï¼å°±è¦æ±æ件æ件å使ç¨å°ååæ¯ãSmarty 2 å 许使ç¨å¤§å°åæ··åæ件åï¼ä½ å¿ é¡»éå½å以ç¨äºsmarty 3. == Smartyç¹æ®åéä½ç¨å ==
å¨Smarty 2ä¸Smartyç¹æ®åé $smarty.section.* and $smarty.foreach.*
æ¥æå ¨å±ä½ç¨åãå¦æå模æ¿ä¸å«æååç循ç¯ï¼å°±ä¼è¦çç¶æ¨¡æ¿ä¸çå¼ãå¨Smarty 3ä¸è¿äºç¹æ®åéå°åªä½ç¨äºå®ä¹å¾ªç¯æå¨ç模æ¿ãè¥æ¯éè¦å¨å模æ¿ä¸ä½¿ç¨ï¼å°±ä¸å¾ä¸ä½¿ç¨åæ°ä¼ éã
<source lang="smarty">
{include file="path/foo.tpl" index=$smarty.section.foo.index}
</source>== SMARTY_RESOURCE_CHAR_SET ==
Smarty 3 设置常é SMARTY_RESOURCE_CHAR_SET 为 utf-8ä½ä¸ºæ¨¡çæ件çé»è®¤å符é.
åªæ¯ä½ä¸ºå escape çå½æ°çé»è®¤å符é. å¦æä½ ç模æ¿ä½¿ç¨å ¶å®å符é, å°±å¿ é¡»èªå·±å®ä¹è¿ä¸ªå¸¸é.== trigger_error()
API å½æ° trigger_error() 已被移é¤ã == Smarty 常é ==
ä¸é¢è¿äºå¸¸é
SMARTY_PHP_PASSTHRU
SMARTY_PHP_QUOTE
SMARTY_PHP_REMOVE
SMARTY_PHP_ALLOW
已被类常éæ¿ä»£
Smarty::PHP_PASSTHRU
Smarty::PHP_QUOTE
Smarty::PHP_REMOVESmarty::PHP_ALLOW追é®
è¿ä¸ªæçå°è¿ï¼åæ ·è°¢è°¢ä½
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-03-07
smarty3中可以直接赋值和使用php的函数的,检查一下smarty的版本和配置是否一致吧。追问
服务器里面的网站系统是使用的Smarty2.0版本 ,本机是Smarty3.0版本,确实是版本问题,但不知道如何解决?怎么升级到3.0版本?之前的程序需要改动吗?