We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Here’s a plugin for phpHyphenator

Development and Programming

KomodoDave's avatar
KomodoDave
39 posts
16 years ago
KomodoDave's avatar KomodoDave

phpHyphenator (http://yellowgreen.de/phphyphenator) can be used to ‘soft hyphenate’ text, akin to newspapers. Words are broken at the end of a line at an appropriate character within the word (usually after a syllable). Here’s a simple plugin to allow use with EE - copy and paste the code into a file ‘pi.hyphenator.php’, then follow the instructions in the code comments.

<?php
// Author:  N David Brown
// License: Freely distributable
//
// Description: Plugin for soft hyphenation of text under ExpressionEngine, using phpHyphenator
//
// Usage:
//
//  i.      Download phpHyphenator latest version from
//
//              http://yellowgreen.de/phphyphenator
//
//  ii.     Extract phpHyphenator to its own directory, then place anywhere within webroot on
//          server
//
//  iii.    Place this file (pi.hyphenator.php) into your ExpressionEngine plugins directory
//          (usually webroot/system/plugins)
//
//  iv.     Modify MY_WEBROOT and MY_PATH_HYPHENATOR accordingly - inline comments explain how
//          (see below in $GLOBALS declarations)
//
//  iii.    Wrap (X)HTML you wish to be soft hyphenated with '{exp:hyphenator}' tags, e.g.
//
//                  {exp:hyphenator}<div></div>{/exp:hyphenator}
//
//  Notes:  If you do not set charset UTF-8 in your HTML within a content-type metatag, you should
//          uncomment the 'header(...)' line in the code below, since phpHyphenator requires UTF-8
//
//
//  For example of phpHyphenator in action, please visit
//
//              http://www.buildingfrombelow.org
//
//      
// Copyright of N David Brown, Jun 2009. Contact: developerdave _at_ gmail _dot_ com

// replace 'change_me' with path to webroot, e.g. /path/to/public_html, or /path/to/htdocs
$GLOBALS["MY_WEBROOT"] = 'change_me';

// replace 'change_me' with path to php hyphenator directory, relative to webroot
$GLOBALS["MY_PATH_HYPHENATOR"] = $GLOBALS["MY_WEBROOT"].'change_me';

$GLOBALS["path_to_patterns"] = $GLOBALS["MY_PATH_HYPHENATOR"].'/patterns/';
$GLOBALS["dictionary"] = $GLOBALS["MY_PATH_HYPHENATOR"].'/dictionary.txt';

include $GLOBALS["MY_PATH_HYPHENATOR"].'/hyphenation.php';

class Hyphenator
{
    var $return_data = "";

    function Hyphenator()
    {
        global $TMPL;
        //header('content-type: text/html; charset=utf-8');
        $this->return_data = hyphenation($TMPL->tagdata);
    }
}
?>

Let me know if you have any problems.

  • Dave
       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill

I’ve used the hyphenator javascript, but this looks like a better approach. I’ve copied your code and loaded the plugin, but nothing is appearing in the plugin page. I don’t see the plugin_info array in the code either. Maybe part of your code is missing?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.