Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

PHP: Random ID illegal character

I have tried it standalone many many times and i got no ID with illegal character. Well, But when the code below working on my website, it is generating illegal characters like: XY�DV3VD, L6XÝOMJ3

The output must consist of [A-Z] and [0-9]. How this could be? Thanks for ideas.

function uniqeeID($len){
 //generate a random id encrypt it and store it in $rnd_id 
 $rnd_id = crypt(uniqid(rand(),1)); 
 //to remove any slashes that might have come 
 $rnd_id = strip_tags(stripslashes($rnd_id)); 
 //Removing any . or / and reversing the string 
 $rnd_id = str_replace(".","",$rnd_id); 
 $rnd_id = strrev(str_replace("/","",$rnd_id)); 
 //finally I take the first $len characters from the $rnd_id 
 $rnd_id = strtoupper(substr($rnd_id,0,$len));
 return $rnd_id;
}

Answer*

Draft saved
Draft discarded
Cancel

lang-php

AltStyle によって変換されたページ (->オリジナル) /