Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Random String Generator PHP Function Programming Tutorial

Learn to program a PHP random string generator that can be as long as you specify. We demonstrate how to then make your script modular in order for it to be reusable, external and dynamic. Splitting (str_split) any string gives you an array from that string, then you can pluck out elements of that array (array_rand) within a for loop in order to return a randomly generated string of characters of any length. <?php function randStrGen($len){ $result = ""; $chars = "abcdefghijklmnopqrstuvwxyz$_?!-0123456789"; $charArray = str_split($chars); for($i = 0; $i < $len; $i++){ $randItem = array_rand($charArray); $result .= "".$charArray[$randItem]; } return $result; } // Usage example $randstr = randStrGen(200); echo $randstr; ?>
thumb

PHP Videos

Miscellaneous

Website Design Theme Application PHP Cookies CSS TutorialPDO Prepared Statements PHP TutorialPDO Tutorial Connect Database and Query ExampleActive Page Link Button Highlight TutorialGeoPlugin Tutorial Get User Location Information IP DetectionHashtag System and Regex PHP Programming TutorialPagination MySQLi Google Style Paged Results TutorialActive Clickable Link Function preg_replace Programming TutorialGet Favicon From Web Site Link Access External FilesRandom String Generator PHP Function Programming TutorialForce File Download Dialog In Browser TutorialCheck User Sign Up Name Ajax PHP Social Network TutorialFlat File Text Database System CMS Edit Content TutorialFlat File Text Database System Display ContentExperience Level Evaluation Programming TutorialStagger and Limit Dynamic Output in a While Loop Google AdsTwitter Dynamic Goodies Widget TutorialDynamic Google Maps Location TutorialPrepared Statements PHP mysqli Tutorial