PHP Typography is a PHP based solution to greatly improve web typography. It features the following capabilities (including granular control):
- Spacing control, including: gluing values to units, widow protection, and forced internal wrapping of long URLs & email addresses.
- Intelligent character replacement, including smart handling of: quote marks ( “foo” ), dashes ( foo – bar ), ellipses ( … ), trademarks ( ™ ), math symbols ( 1024×768 ), fractions ( 12⁄23 ), and ordinal suffixes ( 3rd )
- CSS hooks for styling: ampersands (class “amp”), acronyms (class “caps”), numbers (class “numbers”), initial single quotes (class “quo”), and initial double quotes & guillemets (class “dquo”).
This project merges, builds upon, and generalizes the functionality of wp-Typogrify, wp-Hyphenate and SmartyPants.
While complication is added when manipulating the many options, implementing PHP Typography can be as easy as this:
<?php $html = "raw HTML here... "; include('path/to/php-typography.php'); $typo = new phpTypography(); $html = $typo->process($html); echo $html; ?>
PHP Typography is designed for easy integration with plugin architectures of PHP based content management systems. It has already been ported to WordPress and Zikula CMS. We would like to see other developers pick up this code and implement it for other CMSs. Specifically:
- Expression Engine
If you are a developer for these (or any other PHP based CMS), the heavy lifting is done. You just need to hook it into your CMS.
Here is a fine testimonial from Jenny (who also provided some valuable feedback to further improve the project):
I’ve been evaluating PHP Typography for use in a custom CMS and have been very pleased so far…. It was, as you promised, easy to integrate in our framework (ZF) by wrapping it in a simple class implementing Zend_Filter_Interface. I am using PHP Typography after running the text through HTMLPurifier, and the output has been beautiful thus far.
PHP Typography has the following requirements:
- the host server must run PHP 5 or later
- text must be encoded UTF-8
- all markup must be valid xHTML, specifically:
- every element must be closed,
- every attribute must have a value enclosed in quotes, and
- tag names and attributes must be lowercase.
It should also be noted, PHP Typography would not have been possible without another tool we have recently released: PHP Parser. PHP Parser is an amazingly powerful resource that allows HTML to be parsed, modified and reconstructed in ways previously not possible.
Your feedback is much appreciated. How can we make this plugin better? Have you developed a plugin using PHP Typography? Email us at email@example.com