While working on various web projects written completely in PHP, I collected
some custom procedures for more satisfying work.
Often you are in need of trimming some text by set number of characters, but
do not want to trim mid-word. This is a function which cuts text between words
trying to reduce string length to be less than provided value.
Pretty-printing values of variables
So, you are a web developer. Why are you have to use such stdout-oriented
functions as echo or print? We will dump variables of any complexity using
Additionally, as we know about the existence of highlight.js, we want
to colorize the output if it is sufficiently complex.
MIME encoding of strings
When sending e-mail letters in real multi-national world you need to declare
character encoding on almost anything. To do this in e-mail headers, you should
wrap your header content in special encoding declaration and convert it to
Base64. To speed-up this process, I wrote small helper function.