Page 1 of 1

Smarty syntax help

Posted: Fri Sep 11, 2009 7:23 am
by grimmus
Hi,

I have a UDT that outputs logo images from a certain folder based on what section the user is in.

I need these images to link to their product websites, so i have named the images like
www-google-com.gif, www-facebook-com.gif

My plan is to extract the link from the image name but the smarty syntax isnt working for me.

I need to replace the slashes with dots and remove the file extension (.gif, .jpg etc.)

i have something like

Code: Select all

$files = glob("uploads/images/".$params['id']."/*.*", GLOB_BRACE);

if($files)
{
$folder = $params['id'].'/';

$i=1;
foreach($files as $file)
{
        if(!preg_match('/thumb/',$file))
        {            
             //$image = explode('.',$files[$i]);
             
             $image = explode('-',$files[$i]);
             $im = explode($folder,$image[0]);
             $thumb = explode($folder,$file);
             $path =  $thumb[0].$folder.'/'.$thumb[1];

                  print"<a href='$image[$i]' >";
                  print" <img src='".$path."' />";
                  print "</a>";         
        }        
}

}

Could anyone help me with the syntax ? I want to replace the slashes with dots and remove the file exension (including the dot)

Thanks for any help

Re: Smarty syntax help

Posted: Fri Sep 11, 2009 8:02 am
by Peciura
Why cant you name your files like "www.gooogle.com" ?

You placed your variable "$image[$i]" between ' and '

Code: Select all

<?php
print"<a href='$image[$i]' >";
?>
, i think output is as literal string "".
Try

Code: Select all

<?php
print"<a href=\"$image[$i]\" >";?>
or similar as you have already done

Code: Select all

<?php
print"<a href='".$image[$i]."' >";
?>

Code: Select all

<?php
if(!preg_match('/thumb/',$file)){  
   $path_parts = pathinfo($file);
   $path_parts['filename'];
   print"<a href=' ".str_replace( '-', '.', $path_parts['filename'])." ' >";
   print" <img src='".$file."' />";
   print "</a>"; 
}        
?>
Any way this should help
http://lt2.php.net/manual/en/function.pathinfo.php
http://lt2.php.net/manual/en/function.str-replace.php