Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-10-2009, 04:43 PM   PM User | #1
crazy.works
Regular Coder

 
Join Date: Jul 2008
Posts: 150
Thanks: 24
Thanked 0 Times in 0 Posts
crazy.works is an unknown quantity at this point
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 05:00 PM..
crazy.works is offline   Reply With Quote
Old 03-10-2009, 05:41 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
try to append not to replace:
PHP Code:
$all .= $cut $hash
best regards
oesxyl is offline   Reply With Quote
Users who have thanked oesxyl for this post:
crazy.works (03-11-2009)
Old 03-11-2009, 03:01 AM   PM User | #3
crazy.works
Regular Coder

 
Join Date: Jul 2008
Posts: 150
Thanks: 24
Thanked 0 Times in 0 Posts
crazy.works is an unknown quantity at this point
it doesnt work , any other suggestion please !
crazy.works is offline   Reply With Quote
Old 03-11-2009, 03:12 AM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by crazy.works View Post
it doesnt work , any other suggestion please !
you didn't test it, isn't it?

regards
oesxyl is offline   Reply With Quote
Old 03-11-2009, 03:13 AM   PM User | #5
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
$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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:27 AM.


Advertisement
Log in to turn off these ads.