Pogledajte određenu poruku
Staro 09. 09. 2006.   #2
phoenix
član
Na probnom radu
 
Avatar phoenix
 
Datum učlanjenja: 09.06.2005
Lokacija: Novi Sad
Poruke: 46
Hvala: 0
0 "Hvala" u 0 poruka
phoenix is on a distinguished road
Pošaljite ICQ poruku za phoenix Pošaljite poruku preko MSN za phoenix
Default

Ono sto nadjoh, jeste smarty modifier, ali mozes da ga iskoristis:
PHP kôd:
<?php  
/* 
* Smarty plugin 

------------------------------------------------------------- 
* File:     modifier.html_substr.php 
* Type:     modifier 
* Name:     html_substr 
* Version:  1.0 
* Date:     June 19th, 2003 
* Purpose:  Cut a string preserving any tag nesting and matching. 
* Install:  Drop into the plugin directory. 
* Author:   Original Javascript Code: Benjamin Lupu <lupufr@aol.com> 
*           Translation to PHP & Smarty: Edward Dale <scompt@scompt.com> 
*           Modification to add a string: Sebastian Kuhlmann <sebastiankuhlmann@web.de> 

------------------------------------------------------------- 
*/  
function smarty_modifier_html_substr($string$length$addstring="")  

   
$addstring " " $addstring;    

   if (
strlen($string) > $length) { 
      if( !empty( 
$string ) && $length>) {  
         
$isText true;  
         
$ret "";  
         
$i 0;  
    
         
$currentChar "";  
         
$lastSpacePosition = -1;  
         
$lastChar "";  
    
         
$tagsArray = array();  
         
$currentTag "";  
         
$tagLevel 0;  
    
         
$noTagLength strlenstrip_tags$string ) );  
    
      
// Parser loop 
      
for( $j=0$j<strlen$string ); $j++ ) {  
    
         
$currentChar substr$string$j);  
         
$ret .= $currentChar;  
    
         
// Lesser than event 
         
if( $currentChar == "<"$isText false;  
    
         
// Character handler 
         
if( $isText ) {  
    
            
// Memorize last space position 
            
if( $currentChar == " " ) { $lastSpacePosition $j; }  
            else { 
$lastChar $currentChar; }  
       
            
$i++;  
         } else {  
            
$currentTag .= $currentChar;  
         }  
    
         
// Greater than event 
         
if( $currentChar == ">" ) {  
            
$isText true;  
    
            
// Opening tag handler 
            
if( ( strpos$currentTag"<" ) !== FALSE ) &&   
               ( 
strpos$currentTag"/>" ) === FALSE ) &&   
               ( 
strpos$currentTag"</") === FALSE ) ) {  
    
            
// Tag has attribute(s) 
            
if( strpos$currentTag" " ) !== FALSE ) {  
               
$currentTag substr$currentTag1strpos$currentTag" " ) - );  
            } else {  
               
// Tag doesn't have attribute(s) 
               
$currentTag substr$currentTag1, -);  
            }  
    
            
array_push$tagsArray$currentTag );  
                        
         } else if( 
strpos$currentTag"</" ) !== FALSE ) {  
            
array_pop$tagsArray );  
         }  
                    
         
$currentTag "";  
      }      
    
      if( 
$i >= $length) {   
         break;  
      }  
   }  
    
      
// Cut HTML string at last space position 
      
if( $length $noTagLength ) {          
         if( 
$lastSpacePosition != -) {  
            
$ret substr$string0$lastSpacePosition );  
         } else {  
            
$ret substr$string$j );  
         }  
      }  
    
      
// Close broken XHTML elements 
      
while( sizeof$tagsArray ) != ) {  
         
$aTag array_pop$tagsArray );  
         
$ret .= "</" $aTag ">\n";  
      }  
       
       } else {  
         
$ret "";  
      }  
    
      
// only add string if text was cut 
      
if ( strlen($string) > $length ) {   
         return( 
$ret.$addstring );  
      } 
      else { 
         return ( 
$res ); 
      } 
   } 
   else { 
      return ( 
$string ); 
   }     
}  

/* vim: set expandtab: */  

?>
phoenix je offline   Odgovorite uz citat