Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts

    help me with that function please

    hello ,
    i was trying to make function to insert into number small md5 hash to make it hard to read for special usage , so lets say i have number like "1234" , with my function it gonna be (1xx2xx3xx4xx) ==> x is md5 num

    so i coded the function like that

    PHP Code:
    function code($num)  {
    $count strlen($num);
    $hash substr(md5(rand(0,999)), 152);
           
    $start "0";
        while(
    $count 0) {
    $cut substr($num$start1);
     
    $all $cut.$hash;
      ++
    $start;
      --
    $count;
     }
    return 
    $all ;


    but it doesnt return with the full number, it returns with the last x number cazue of while , and if i added echo $all; between while tags it gonna print the all number like that

    PHP Code:
     $all $cut.$hash;
      echo 
    $all;
      ++
    $start;
      --
    $count

    so please how can i make the function returns with the full number $cut.$hash (1xx2xx3xx4xx) ??

    thanks
    Last edited by crazy.works; 03-10-2009 at 06:00 PM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try to append not to replace:
    PHP Code:
    $all .= $cut $hash
    best regards

  • Users who have thanked oesxyl for this post:

    crazy.works (03-11-2009)

  • #3
    Regular Coder
    Join Date
    Jul 2008
    Posts
    150
    Thanks
    24
    Thanked 0 Times in 0 Posts
    it doesnt work , any other suggestion please !

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by crazy.works View Post
    it doesnt work , any other suggestion please !
    you didn't test it, isn't it?

    regards

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    $start should be an int not a string though php should convert it on the fly. This seems to work
    PHP Code:
    <?php
    function code($num)
    {
        
    $all '';
        
    $count strlen($num);
        
    $hash substr(md5(rand(0,999)), 152);
        while(
    $count 0)
        {
            
    $cut substr($num$start1);
             
    $all .= $cut.$hash;
              ++
    $start;
              --
    $count;
          }
        return 
    $all;
    }
    echo 
    code(1234);
    ?>
    FYI it would have worked with your original code if you just used $all .= $cut . $hash as suggested which is exactly what I did.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •