用于图像的Smarty cdn输出过滤器


Smarty cdn output filter for images

smarty的输出过滤器,它用您的cdn URL 替换smarty模板中的图像URL

例如像这样的图像

<img src="/images/image.gif"/>
<img src="http://cdn.yoursite.com/images/image.gif"/>

我认为有这样的

<?php  function smarty_outputfilter_cdn($tpl_source, &$smarty)  {      if($_SERVER["SERVER_PORT"] == 80) {          $tpl_source = preg_replace('/("|'')(('.'/|'/)[A-z0-9_'-'/@'.]+'.(jpg|jpeg|gif|png))("|'')/i', "'"http://cdn.yoursite.com''2'"", $tpl_source);      }            return $tpl_source;  }  ?>