Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,668 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,145 people online right now. Registration is fast and FREE... Join Now!




Strtoupper?

 
Reply to this topicStart new topic

Strtoupper?

k0b13r
post 6 Aug, 2007 - 12:53 PM
Post #1


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Hi. I wanted to improve password generation script (http://www.dreamincode.net/code/snippet641.htm) a bit. I wanted to change every second letter to upper-case. So I added some code:
CODE

function password_generator($lenght=8)
{
    for($i = 0; $i <= $lenght; $i++)
    {
        $password .= chr(rand(97,122));
// Changes few letters to numbers
        switch($password[$i])
        {
            case a:
            $password[$i] = 4;
            break;
            case b:
            $password[$i] = 8;
            break;
            case e:
            $password[$i] = 3;
            break;
            case i:
            $password[$i] = 1;
            break;
            case o:
            $password[$i] = 0;
            break;
            case s:
            $password[$i] = 5;
            break;
        }
// New part
        $even = $i/2;
        if(is_int($even))
        {
            strtoupper($password[$i]);
        }
    }
    echo "Your new password is \"".$password."\"";
}
password_generator();
?>


But it's not working confused.gif Everything is still lowercase. Any suggestions?
Thnx for answers

This post has been edited by k0b13r: 6 Aug, 2007 - 01:00 PM
User is offlineProfile CardPM

Go to the top of the page

snoj
post 6 Aug, 2007 - 01:09 PM
Post #2


$Null

Group Icon
Joined: 31 Mar, 2003
Posts: 3,304



Thanked 5 times

Dream Kudos: 700
My Contributions


Because strtoupper() returns the upper case string. It doesn't pass the variable by reference.

Try $password[$i] = strtoupper($password[$i]); instead.
User is offlineProfile CardPM

Go to the top of the page

k0b13r
post 6 Aug, 2007 - 01:13 PM
Post #3


D.I.C Head

Group Icon
Joined: 18 Jul, 2006
Posts: 196



Thanked 1 times

Dream Kudos: 250
My Contributions


Works perfect now smile.gif Thanks hotsnoj
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:56AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month