Visualizzazione dei risultati da 1 a 4 su 4

Hybrid View

modografico Sillabatore PHP (italiano) 31-07-2014, 00:12
badaze Forse non ho letto bene, ma... 31-07-2014, 10:55
modografico prima vanno però verificate... 31-07-2014, 11:34
badaze Se guardi le tue condizioni,... 31-07-2014, 18:44
  1. #1

    Sillabatore PHP (italiano)

    forse potrà servire e sicuramente migliorare.

    Codice PHP:
    <?php
    /**
     * Hyphenation - sillabatore
     * PHP Library for the hyphenation
     * @author Raffaello Regoli <info@modografico.com>
     * @copyright Copyright (c) 2014, Raffaello Regoli
     */ 
     
    function isV($str){
        
    $v="aeiouy";
        for(
    $n=0;$n<strlen($v);$n++){
            if(
    $str==$v{$n})return true;
        }
    }
    function 
    isC($str){
        
    $v="bcdfgjpqstvwxz";
        for(
    $n=0;$n<strlen($v);$n++){
            if(
    $str==$v{$n})return true;
        }
    }
    function 
    isL($str){
        
    $v="hlmnr";
        for(
    $n=0;$n<strlen($v);$n++){
            if(
    $str==$v{$n})return true;
        }
    }
    function 
    isN($str){
        
    $v="0123456789";
        for(
    $n=0;$n<strlen($v);$n++){
            if(
    $str==$v{$n})return true;
        }
    }
    function 
    doHYPHEN($string$start){
        
    $len=strlen($string);
        for(
    $n=$start;$n<$len-1;$n++){
            
    $a=strtolower($string{$n});
            
    $b=strtolower($string{$n+1});
            
    $c=strtolower($string{$n+2});
            if((!
    isN($a) and !isN($b)) or $a!="s"){
                if(
    $a==" "){//è uno spazio
                    
    $hyphen[0]=substr($string0$n+1);
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //sono lettere doppie
                
    if($a==$b and $n<$len-and $c!=" "){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //vocale + s
                
    if(isV($a) and $b=="s"){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //liquida + s
                
    if(isL($a) and $b=="s"){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //vocale + consonante + vocale
                
    if(isV($a) and isC($b) and isV($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //vocale + consonante + liquida
                
    if(isV($a) and isC($b) and isL($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //liquida + consonante + vocale
                
    if(isL($a) and isC($b) and isV($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //liquida + consonante + liquida
                
    if(isL($a) and isC($b) and isL($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //vocale + liquida + vocale
                
    if(isV($a) and isL($b) and isV($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                
    //liquida + liquida + vocale
                
    if(isL($a) and isL($b) and isV($c)){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }        
            }
        }
        
    $hyphen[0]=$string;
        return 
    $hyphen;
    }
    function 
    hyphenation($str$len){
        
    $a=doHYPHEN($str$len);
        
    $strHYP="$a[0]";
        while(
    strlen($a[1])>$len){
            
    $a=doHYPHEN($a[1], $len);
        
        
    $strHYP.="<br>$a[0]";
    }
        
    $strHYP.="<br>$a[1]";
        return 
    $strHYP;
    }
    function 
    troncaparola($str$len){
        
    $a=doHYPHEN($str$len);
        
    $strHYP="$a[0]";
        
    //while(strlen($a[1])>$len){
            //$a=doHYPHEN($a[1], $len);
        
        //$strHYP.="<br>$a[0]";
    //}
        
    $strHYP.="<br>$a[1]";
        return 
    $strHYP;
    }
    /*
    //per sillabare una parola:
    //es.:
    $string="ermafrodito";
    $len=0;    
    $word=hyphenation($string, $len);
    print($word);
    //per troncare una parola:
    //es.:
    $string="ermafrodito";
    $pos=2;    
    $word=troncaparola($string, $pos);
    print($word);
    */
    ?>

  2. #2
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Forse non ho letto bene, ma penso si potrebbe rimpiazzare gran parte del codice di doHYPEN con

    Codice PHP:
                    $hyphen[0]=substr($string0$n+1);
                    if (
    $a != " ") { $hyphen[0] .="-";}                
                    
    $hyphen[1]=substr($string$n+1);                
                    return 
    $hyphen
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

  3. #3
    Quote Originariamente inviata da badaze Visualizza il messaggio
    Forse non ho letto bene, ma penso si potrebbe rimpiazzare gran parte del codice di doHYPEN con

    Codice PHP:
                    $hyphen[0]=substr($string0$n+1);
                    if (
    $a != " ") { $hyphen[0] .="-";}                
                    
    $hyphen[1]=substr($string$n+1);                
                    return 
    $hyphen
    prima vanno però verificate le condizioni e dopo se soddisfatte si tronca la parola
    si potrebbe rifare il codice così:

    Codice PHP:
    function doHYPHEN($string$start){
        
    $len=strlen($string);
        for(
    $n=$start;$n<$len-1;$n++){
            
    $a=strtolower($string{$n});
            
    $b=strtolower($string{$n+1});
            
    $c=strtolower($string{$n+2});
            if((!
    isN($a) and !isN($b)) or $a!="s"){
                if(
    $a==" "){//è uno spazio
                    
    $hyphen[0]=substr($string0$n+1);
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
                if((
    $a==$b and $n<$len-and $c!=" ") or (isV($a) and $b=="s") or (isL($a) and $b=="s") or (isV($a) and isC($b) and isV($c)) or (isV($a) and isC($b) and isL($c)) or (isL($a) and isC($b) and isV($c)) or (isL($a) and isC($b) and isL($c)) or (isV($a) and isL($b) and isV($c)) or (isL($a) and isL($b) and isV($c))){
                    
    $hyphen[0]=substr($string0$n+1)."-";
                    
    $hyphen[1]=substr($string$n+1);
                    return 
    $hyphen;
                }
            }
        }
        
    $hyphen[0]=$string;
        return 
    $hyphen;

    più che altro era per comodità di lettura del codice

  4. #4
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Se guardi le tue condizioni, la prima è esclusiva nel senso che non si riscontra più altrove e quindi dal momento in cui non si passa dentro sarà una delle altre condizioni ad essere eseguita. Dunque se dopo la prima hai messo tutte le condizioni possibili, in ogni caso viene eseguito lo stesso codice dal momento in cui non si è passati dalla prima.
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

Tag per questa discussione

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.