Before I get back on the road yet again, here’s a quick little (horrible) PHP snippit. A friend of mine is learning PHP, and asked me how to strip all of the ‘unprintable’ characters out of a string. ctype_alpha() can not be considered portable enough yet, and of course, there is no isascii() in PHP… not to mention that PHP’s string manipulation is haphazard and slow – at best.
Here’s what I ended up giving him. It’s a trivial little hack that accepts two variables; a string (of course), and a boolean, “dots” to replace unprintable characters with periods. It’s highly tied to the ASCII character set.
function nonascii_string_cleaning($myText, $dots = FALSE) {
$trans_array = array();
// This is the lower (unprintable) ASCII character set
for ($i = 0; $i < 32; $i++) {
$trans_array[chr($i)] = ($dots) ? ”.” : “”;
}
// This is the “higher” (unprintable) ASCII character set
for ($i = 129; $i < 255; $i++) {
$trans_array[chr($i)] = ($dots) ? ”.” : “”;
}
$replaced = strtr($myText, $trans_array);
return $replaced;
}
Horrid Example (Yes, this is what he wanted to do:)
It’s pretty simple, if not mostly-useless. Still, this makes me wish there were more C-like functions in PHP. Come on, guys! This would have been much better with isalpha() and an intelligent getchar() type of ordeal. Sure, it’s possible to use a file handle, or pass things as an array; but with my testing, and his requirement of it accepting a string, this came out about as fast and ‘bare wire’ as possible, while still being legible. Note my use of the ternary operators. ;)
A friend across-country found this in the paper today, and knowing that I lived in the San Francisco area felt the “need” to forward it on. Thanks, SG – it gave myself, and a few other local friends a nice chuckle.
For the last few months, my bandwidth use as been increasing; and my pageviews have stayed relatively the same. Upon researching this, I’ve discovered that many places are now “hotlinking” directly to my programs, which means that the user might no idea what, or where they are getting the software from. Worse, they most likely are unaware of whom to contact for support!
As mentioned in this post on my forums; I now do a test to see if my files are being referenced locally, or from one of my other sites. If this is the case, the file will download as normal; otherwise, the user will be redirected to my software page.
It’s my fault. I admit it. Upon hearing of a primary author of the MacOS X port of VLC “dropping out” for a spell; I wanted to make sure that I’d be able to continue to play my files!
I thus opted to attempt to update MPlayer. MPlayer OSX is horribly out of date, and rather slow. Horribly so. I decided to utilize the newer 1.0pre3 software, and after a few bugs and excessive work to compile everything statically, I pass the savings on to you with a speedy recent incarnation!