Michael Michael

Web Development & Graphic Design | Monkey Tooth Productions

Www Michaeltriller W U U Berry Berry Cheap En Na Le District Michael Triller

however outside of that I cant really vouch for the other libraries and there support on the subject as I prefer jQuery and use that over the rest when ever possible (unless I am working on a clients site and they have something different from jQuery)

no comments   |  tags: , , , | posted in Coding


Jun 23 2010

PHP create a random string of Alpha/Numeric Characters

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

no comments   |  tags: , , | posted in Coding, PHP


Jun 22 2010

PHP truncate/shorten string, variable, text

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…

y Web Development & Graphic Design | Monkey Tooth Productions d Michael r Web Development & Graphic Design | Monkey Tooth Productions f Triller c c Michael Michael