Parsing human names are not exactly easy, but they can be done. Keith Beckman’s nameparse.php is an excellent PHP library for doing this.
Download nameparse.php
nameparse.php can recognize names in “[title]first[middles]last[,][suffix]” and “last,first[middles][,][suffix]” forms, which, when you think about it, cover most if not all well-formed name input formats. nameparse.php handles last names of arbitrary complexity, such [...]
Here’s the surprisingly simple solution to a fairly challenging problem. I do not understand why PHPs GMP extension does not include a gmp_not() function.
function gmp_not($n) {
# convert to binary string
$n = gmp_strval($n, 2);
# invert each bit, one at a time
for($i = 0; $i < strlen($n); $i++) {
$n[$i] = ~$n[$i];
}
# convert back to decimal
return gmp_strval(gmp_init($n, 2), [...]
After some digging, I found a great way to convert number bases when dealing with arbitrary length integers (esp. integers > 32 bits):
return gmp_strval(gmp_init($n, 2), 10);
This will convert a large base 2 (binary) number to base 10 (decimal).
I got this question from a reader and thought it would be useful to post for everyone:
Hi Jonathon,
I really like some of your solutions to making things simpler when using CodeIgniter. On the subject, I was wondering if you had a preference for a simple way to include headers and footers in your views. [...]
Using register_shutdown_function() to do stuff on script shutdown requires special error handling. Normal error handling does not work within the function called, so if an error occurs inside your shutdown function you get this nondescript error:
Fatal error: Exception thrown without a stack frame in Unknown on line 0
The solution was to catch the exception and [...]