thenewperson Posted November 6, 2009 Share Posted November 6, 2009 Wondering how i would take first 10 letters/numbers from random string current code but failed The number works but trying to take first 10 failed <?php $id = md5(uniqid(rand())); echo strpos($id, 10); ?> Link to comment https://forums.phpfreaks.com/topic/180515-solved-need-simple-php-string-help/ Share on other sites More sharing options...
Alex Posted November 6, 2009 Share Posted November 6, 2009 Use substr() echo substr($id, 0, 10); Link to comment https://forums.phpfreaks.com/topic/180515-solved-need-simple-php-string-help/#findComment-952312 Share on other sites More sharing options...
thenewperson Posted November 6, 2009 Author Share Posted November 6, 2009 Use substr() echo substr($id, 0, 10); ty that worked Link to comment https://forums.phpfreaks.com/topic/180515-solved-need-simple-php-string-help/#findComment-952313 Share on other sites More sharing options...
gizmola Posted November 6, 2009 Share Posted November 6, 2009 FYI, that is not a "random string". You are taking only a portion of a hash, so there's a strong possibility you will have duplicates.. You might try writing a test program to spit out a few thousand variations and make sure you don't have colisions -- assuming that you care about that. Link to comment https://forums.phpfreaks.com/topic/180515-solved-need-simple-php-string-help/#findComment-952324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.