PHP Scripts and Tools
PHF_Get: Download webpages into a single portable file
Current Version - 0.3.2 (beta)Use this tool
Encode text in UTF-8 or HTML Entities
Current Version - 1.2Use this tool
Are you serving your pages in UTF-8 and want to include some characters other than those your keyboard can give? Unless you have an editor capable of understanding UTF-8, trying to insert these special characters (eg. µ, ä or 中文) as-is causes blank characters or question marks to appear. This tool will take whatever characters you supply and serve them back encoded in UTF-8, easily copied and pasted into your own HTML documents.
Want to paste special characters into documents which don't use a UTF-8 charset? Then you'll need to use HTML entities like these:
中文. This tool will also allow you to translate any string of characters into HTML entities which should display the proper characters in any charset.
htmlwrap - Safely wrap HTML formatted text
Current Version - 1.7Use this tool
Built for use in the Orca Forum and Blog, the
htmlwrap()function safely wraps HTML formatted text by breaking strings of characters over a certain length. It's great for use anywhere where generated HTML output is built from user input.
htmlwrap()won't insert line-breaks within HTML tags or entities, and entities are all treated as single characters when calculating break-points. It will also try to find logical line-break insertion points (like after periods or slashes) instead of pounding them in robotically every certain number of characters. Additionally, you can protect entire elements from line-breaks just by adding it to the protect list.
Now optionally works on multi-byte characters in version 1.1!
Image to Base64 encoder
Current Version - 1.3Use this tool
The newest browsers supporting the latest CSS allow you to do something amazing: embedding images in CSS files. You do this by translating an image file into base64 and letting the browser build the image as it parses your stylesheet. Now you can distribute stylesheets without bundling them with separate graphics and background files! Just use this Binary file to Base64 translator and paste the output into your CSS or XML file as shown and you'll have instant embedded images.
Auto-trim Text to Image
Current Version - 1.3Get the code
In PHP, in order to create an image box big enough to hold a selection of text, you use the function
imagettfbbox(). However, for some complex fonts, the box isn't always perfect. Descenders might be cut off, or there could be a big space to the right of the end of the text. Angles are especially troublesome to deal with.
The Auto-trim script allows you to create an image from text which is trimmed to a specified border width before sending the result to the browser. This means your images are always the smallest they can be without chopping off any text bits. The script accepts many optional
$_GETvalues, like point size, text colour, and background colour. Other values like angle, and x/y-squeeze can be set within the script itself. Version 1.3 changes the way the initial box dimensions are calculated which makes the script faster in most situations, and avoids some problems with multi-line texts.
Encoding Conversion Functions
These days, I use separate encoded text files for languages; one using UTF-8 and one using the traditional character encoding of the text. In the past, I translated the traditionally encoded text to UTF-8 on the fly, which only required one language file, but turned out to be too much of a hassle to keep up. Nevertheless, the recoding functions I translated into PHP from the original Perl module NexTrieve::UTF8, turned out to be useful in their own right.
There do exist PHP functions which convert any character encoding to any other with ease. However, because they're new, and/or require special compiled modules to use, they aren't always available to everyone. The functions below rely on basic low-level byte-by-byte conversion.
- ISO-8859-9 to UTF-8
- This simple function recodes an iso-8859-9 (Turkish) encoded string into UTF-8. I used this function for the Turkish language file distributed with the Orca Ringmaker.
- ISO-8859-2 to UTF-8
- This simple function recodes an iso-8859-2 (Polish) encoded string into UTF-8. I used this function for the Polish language file distributed with the Orca Knowledgebase.
- Win-874 to UTF-8
- This simple function recodes a windows-874 (Thai) encoded string into UTF-8. I used this function for the Thai language file distributed with the Orca Forum.