Have a need for a quick random string of any given length but want to limit it to a-z 0-9. Then this would be ideal for you, I really can’t think of any real world use for this. Well no thats wrong, you can use it as a random password generator. Or something to the effect of that.
<?php function genRandomString($howbig) {} return $string; } echo "<strong>5 char string:</strong> ". genRandomString('5') ."<br />"; echo "<strong>10 char string:</strong> ".genRandomString('10')."<br />"; echo "<strong>15 char string:</strong> ".genRandomString('15')."<br />"; echo "<strong>20 char string:</strong> ".genRandomString('20')."<br />"; echo "<strong>50 char string:</strong> ".genRandomString('50')."<br />"; ?>
Example of use:
5 char string: ccmys
10 char string: ljpixn86ie
15 char string: ug56okbe5cikv
20 char string: wim6xwaohtqsii59c1
50 char string: u646k6mhblk4zedi8qsdktnn412mfp9etnzap1wlvk3tq0fh7
Every now and again on my projects I come into a spot where I have limited room to display any given amount of text that is generated and updated dynamically. Example I have a length of text thats 400 some odd characters long. I only have room for 120 characters. “So what do I do?” If your asking yourself that question then I have an answer for you, keep in mind not THE answer as there are better solutions out there that will trim truncate any given string down to the number you want but leaving full words in tact at the end rather then cut them off mid word. This function I will show you here that I made for myself a while back is expandable to do such things however I haven’t ran into the need or desire to expand it as such myself as it works for what I use it for without problem.
<?php function ShortenText($text, $chars) {} return $text; } $myText = "Welcome to Monkey Tooth Productions."; echo ShortenText($myText, 20); ?>
Translates to:
Welcome to Monkey…