Visualizzazione dei risultati da 1 a 4 su 4

Discussione: Caratteri minuscoli

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072

    Caratteri minuscoli

    Ciao a tutti, avrei bisogno di un aiuto per la gestione di caratteri in PHP

    1) come posso trasformare in minuscolo una stringa??

    2) ho una stringa del tipo ABCDEDFG
    io devo "estrarre" le due lettere in quarta e quinta posizione .... trasformarle in minuscole .... e riposizionarle in quella posizione

    Grazie

  2. #2
    Utente di HTML.it L'avatar di Grino
    Registrato dal
    Oct 2004
    Messaggi
    739
    codice:
    <?php
    $str="ABCDEFGHI";
    function strtolowerindex($str, $array) {
        $strret = "";
        if (($len = strlen($str)) != 0)
            for ($pos = 0; $pos < $len; $pos++)
                if (array_search($pos, $array)===false)
                    $strret.=substr($str, $pos, 1);
                else
                    $strret.=strtolower(substr($str, $pos, 1));
                    
        return $strret;
    }
    echo strtolowerindex($str, array(4,5))."
    
    ";
    
    //oppure
    
    $str="ABCDE";
    function strtolowerindexed($str, $array) {
        $len=strlen($str);
        sort($array);
        foreach($array as $value)
            if($len>$value)
                $str[$value]=strtolower ($str[$value]);
            else
                break;
        return $str;
    }
    echo strtolowerindexed($str, array(4,5))."
    
    ";
    
    //oppure
    
    $str="ABCDEFGHI";
    $str[4]=strtolower($str[4]);
    $str[5]=strtolower($str[5]);
    echo $str;
    ?>

  3. #3
    Utente di HTML.it L'avatar di dottwatson
    Registrato dal
    Feb 2007
    Messaggi
    3,012
    o semplicemente
    Codice PHP:
    <?php
    $str
    ='ABCDEDFG';

    $els=str_split($str);
    foreach(
    $els as $key=>$letter){
        if(
    $key ==|| $key ==
            
    $els[$key]=strtolower($els[$key]);
        }
    $str=implode('',$els);

    echo 
    $str."
    "
    ;

    //oppure

    $str='ABCDEDFG';
    for(
    $x 0$x strlen($str); $x++)
        if(
    $x == || $x == 5$str{$x}=strtolower($str{$x});

    echo 
    $str;
    ?>
    Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle

    il mio profilo su PHPClasses e il mio blog laboweb

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2006
    Messaggi
    3,072
    Grazie per l'aiuto!!!

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.