PHP Typography 1.21

Features

PHP Typog­ra­phy is a PHP based solu­tion to greatly improve web typog­ra­phy. It fea­tures the fol­low­ing capa­bil­i­ties (includ­ing gran­u­lar control):

  • Hyphen­ation
  • Spac­ing con­trol, includ­ing: glu­ing val­ues to units, widow pro­tec­tion, and forced inter­nal wrap­ping of long URLs & email addresses.
  • Intel­li­gent char­ac­ter replace­ment, includ­ing smart han­dling of: quote marks ( “foo” ), dashes ( foo – bar ), ellipses ( … ), trade­marks ( ™ ), math sym­bols ( 1024×768 ), frac­tions ( 1223 ), and ordi­nal suf­fixes ( 3rd )
  • CSS hooks for styling: amper­sands (class “amp”), acronyms (class “caps”), num­bers (class “num­bers”), ini­tial sin­gle quotes (class “quo”), and ini­tial dou­ble quotes & guillemets (class “dquo”).

This project merges, builds upon, and gen­er­al­izes the func­tion­al­ity of wp-​​Typogrify, wp-​​Hyphenate and SmartyPants.

Implementation

While com­pli­ca­tion is added when manip­u­lat­ing the many options, imple­ment­ing PHP Typog­ra­phy 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 Typog­ra­phy is designed for easy inte­gra­tion with plu­gin archi­tec­tures of PHP based con­tent man­age­ment sys­tems. It has already been ported to Word­Press and Zikula CMS. We would like to see other devel­op­ers pick up this code and imple­ment it for other CMSs. Specifically:

  • Dru­pal
  • Joomla
  • Expres­sion Engine

If you are a devel­oper for these (or any other PHP based CMS), the heavy lift­ing is done. You just need to hook it into your CMS.

Testimonial

Here is a fine tes­ti­mo­nial from Jenny (who also pro­vided some valu­able feed­back to fur­ther improve the project):

I’ve been eval­u­at­ing PHP Typog­ra­phy for use in a cus­tom CMS and have been very pleased so far…. It was, as you promised, easy to inte­grate in our frame­work (ZF) by wrap­ping it in a sim­ple class imple­ment­ing Zend_​Filter_​Interface. I am using PHP Typog­ra­phy after run­ning the text through HTMLPu­ri­fier, and the out­put has been beau­ti­ful thus far.

Requirements

PHP Typog­ra­phy has the fol­low­ing requirements:

  • the host server must run PHP 5 or later
  • text must be encoded UTF-​​8
  • all markup must be valid xHTML, specifically:
    • every ele­ment must be closed,
    • every attribute must have a value enclosed in quotes, and
    • tag names and attrib­utes must be lowercase.

Related

It should also be noted, PHP Typog­ra­phy would not have been pos­si­ble with­out another tool we have recently released: PHP Parser. PHP Parser is an amaz­ingly pow­er­ful resource that allows HTML to be parsed, mod­i­fied and recon­structed in ways pre­vi­ously not possible.

Your feed­back is much appre­ci­ated. How can we make this plu­gin bet­ter? Have you devel­oped a plu­gin using PHP Typog­ra­phy? Email us at info@​kingdesk.​com

Comments

  1. A com­menter on the wp-​​Typography project noti­fied us a false pos­i­tive was returned when the wp-​​Typography project files were scanned by Avira anti-​​virus. This issue appears to also occur with the PHP-​​Typography project.

    We have con­firmed false pos­i­tives for the cy.php, en-GB.php, es.php, ga.php, hr.php, and pr.php lan­guage files. We have been unable to divine the cause. We have reported the false pos­i­tives to Avira and pro­vided them with a copy of the files.

    Avira’s review of the faslse pos­i­tives may be viewed here.

    We have also tested the files in AVG, and are happy to report no false pos­i­tives with their anti-​​virus solution.

  2. From your arti­cle I def­i­nitely think that PHP typog­ra­phy sounds great. I will down­load it, try it and will con­tact you after that.


    Web­de­sign Stuttgart

  3. Does the hyphen­ation pro­vide an excep­tion for cap­i­tal­ized words? I love the Hyphen­ate plu­gin, but pro­tect­ing proper nouns is essen­tial for many pub­li­ca­tions, so I can’t use it if I can’t fil­ter cap­i­tal­ized words.

  4. @Stephen Coles #24

    A new method set_hyphenate_title_case() was added to ver­sion 1.5 to meet your need.

  5. The new WP-​​MU beta plu­gin is great news. I tried it out, and this time it actu­ally works under MU as well. Or at least, I can change the hyphen­ation lan­guage this time…
    :-)

    BTW: A ter­rific fea­ture would be if the default hyphen­ation lan­guage would be the same as the blog lan­guage. Even more so on a MU site, when I acti­vate that plu­gin for all blogs. And how would you deal with a mul­ti­lan­guage blog? Most of the blogs on my MU install are ger­man, some of them eng­lish, and a few are multi-​​language (ger­man, eng­lish, french, maybe ital­ian, take your choice — the last three are offi­cial lan­guages within Switzer­land), where the user can switch to his favorite lan­guage on-​​the-​​fly.

    Thanks a lot for a won­der­ful plu­gin!
     – Daniel

  6. Hi,

    the typog­ra­phy plu­gin is really great. It just hap­pens to make a mis­take with dates writ­ten in ISO for­mat, e.g. “2009 – 08-​​02″. In these, the first hyphen is enlarged, the sec­ond is not. The whole date looks quite gar­bled. Per­haps you can fix that in some new release? Apart from this, the pro­duced out­put is really nice and improves the “usage expe­ri­ence” of “the aver­age blog” quite con­sid­er­ably. Thank you!

    Best regards,
    Dirk

  7. @Dirk Hill­brecht #5

    Thank you for bring­ing this issue to my atten­tion. It has been cor­rected in ver­sion 1.8

  8. …just installed 1.8 and date for­mat­ting now works mar­vel­lous. Thanks again for this great piece of soft­ware! Dirk

  9. There seems to be bug in style_​initial_​quotes(). All 3 mb_​substr() there are with­out encod­ing para­me­ter. Only after adding “UTF-​​8″ it works.

  10. While inte­grat­ing this with my project (run­ning on Kohana VO3) I ran into some prob­lems. It works great until it finds any tags, classes, or IDs set to ignore. I’m not sure what the prob­lem is, but when I try to add any­thing that is listed in the settings[“ignoreTags”], settings[“ignoreClasses”], or settings[“ignoreIDs”] arrays of the php­Ty­pog­ra­phy class, I get an error that says the following:

    ErrorEx­cep­tion [ Notice ]: Unde­fined index: openPos.

  11. @Priit Pirita #8 & Bill # 9,

    Both your issues should be resolved in the new ver­sion 1.19 release.

  12. I found a bug in ver­sion 1.19: on line 1950, $encod­ings is used with­out being ini­tial­ized. Oth­er­wise, works great!

  13. @Erik Spann #12

    Thanks for point­ing this out. I have updated this post with a link.

  14. @Andrew Hutch­ings #11

    Thank you for point­ing this out. It will be addressed in ver­sion 1.20.

  15. Hi,

    Is it pos­si­ble to add two replace­ment pos­si­bil­i­ties : the strait quote to the curly one in any case; and the punc­tu­a­tion replacement.

    The punc­tu­a­tion replace­ment has its inter­est with french lan­guage, where dou­ble punc­tu­a­tion signs (as “;”, “:”, “?” or “!”) must be pre­ceded by an inse­ca­ble space.

    Thanks for your essen­tial wp plu­gin and this php library.

  16. Hi Jeff,

    Found a bug in ver­sion 1.20. php-typography.php, line 412, $cus­tom­Re­place­mentChunks is not ini­tial­ized. From your inden­ta­tion it looks like most of the func­tion is sup­posed to be wrapped in the if state­ment, but you left out the curly brackets.

  17. @Jenny #16

    Yeah, that is some of the ugli­est code I have writ­ten. I fixed it in ver­sion 1.21 about a week ago, but haven’t got to post­ing it yet. I will try to get it up today.

  18. @Jenny #16

    Finally got around to post­ing 1.21. your issue should be resolved.

Leave a Comment

Please note our comment and privacy policies.

(required)
(required)

Trackbacks

  1. […] here: PHP Typog­ra­phy 1.0 beta 4 • KING­desk Share and […]

  2. […] A script named php-​​typography (Also avail­able in a word­press plu­gin) enables more advanced type­set­ting options. Some […]

  3. […] wp-​​Typography ist­nieje także jako zwykły kod PHP, który można przys­tosować do włas­nych potrzeb (np. w innych niż Word­Press CMS-​​ach). Szczegółowe infor­ma­cje na ten temat dostępne są na stronie inter­ne­towej autora (PHP Typography). […]

  4. […] sagen wäre: die Auto­ren stel­len die Funk­tio­nen auch ohne Word­press zum Ein­bin­den in eigene PHP-​​Projekte zur Ver­fü­gung Diese Icons ver­lin­ken auf Book­mark Dien­ste bei denen Nut­zer neue Inhalte […]

  5. […] mas sim­ple con este plu­gin. wp-​​Typography es un proyecto de KING­desk y su código se basa en el PHP Typog­ra­phy. Al ser con­fig­u­rado como nos sea mas con­ve­niente, pro­cede a hacer reem­pla­zos automáti­cos de […]

  6. […] wp-​​Typography WP-​​Typography is one for all the type nerds out there. It adds hyphen­a­tion, spa­cing con­trol, intel­li­gent char­ac­ter replace­ment, and CSS hooks, all of which greatly improve the look and feel of your blog. At the moment I have the hyphen­a­tion, char­ac­ter replace­ment, and widow pre­ven­tion turned on. […]

  7. […] Ist halt lei­der schwierig wenn’s nicht nach den US-​​Regeln gehen soll. Pro­biert mal die von Kingdesk […]

  8. […] PHP Typog­ra­phy 1.12 que viene tam­bién como plu­gin para WordPress […]

  9. […] can eas­ily be ported to any other PHP based con­tent man­age­ment sys­tem. A sis­ter project — PHP Typog­ra­phy assem­bles all typo­graphic func­tion­al­ity (with­out any Word­Press spe­cific code) in an object oriented […]

  10. […] top right are now picked from all the images pos­ted so far. Finally, thanks to the won­der­ful php-​​​typography class the typo­graphy of the posts should be cleaner, and best of all: there’s now […]