PHP template system, image paths
I'm making a basic templating system in PHP, the problem is:
I have a main request handler where from where everything is loaded and processed, but because of that the paths inside the CSS template I downloaded aren't correct anymore.
Example :
<img src="assets/images/contact.gif" />
has to be:
<img src="templates/grey-box/assets/images/contact.gif" />
Is there any way to fix this,开发者_如何学Go PHP wise?
Don't be lazy
- Always use an absolute path. 
- Make it explicit, not with some dirty hacks. It will be a support nightmare. 
- You can use some helper variables, like - $tpl_assets_pathand use it in the template.
Absolute path starts  from / where / designates web-seite root.
And every path on your HTML page should be.
So, the template should be either
<img src="/templates/grey-box/assets/images/contact.gif" />
or
<img src="<?=$tpl_assets_path?>images/contact.gif" />
define('HTTP_SERVER', 'http://www.myhomeurl.com/');
<img src="<?php echo HTTP_SERVER?>assets/images/contact.gif />
it's here
$imgarray = array('assets','script','css');
$tpl = '/templates/grey-box/';
foreach($imgarray as $i){
  $tpldir = $tpl.$i;
  $str = preg_replace("/([^\/])($i)([\/])/i","\$1$tpldir\$3",$str);
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论