nystudio107/php-typography

The KINGdesk PHP Typography library improves typography on the web.

Fund package maintenance!
khalwat

1.0.0 2017-10-15 23:49 UTC

This package is auto-updated.

Last update: 2024-08-29 04:20:04 UTC


README

PhpTypography is based on the PHP Typography library by KINGdesk. It is extended to support the PSR-0 autoloading standard.

Installation

Install PhpTypography with composer via

composer require debach/php-typography:dev-master
composer install

and then use the class like

$html       = '...';
$typography = new Debach\PhpTypography\PhpTypography();
$prettyHtml = $typography->process($html);

What PhpTypography does

PhpTypography enhances the typography of the text on your web pages. The following table shows some examples of HTML texts before and after processing.

For more examples, see the project homepage.

How to use PhpTypography

Construct an instance $typography of Debach\PhpTypography\PhpTypography and call $typography->process($html) on it with the HTML text $html you want to process:

$html       = '<p>I\'m waiting for "Peter"...</p>';
$typography = new Debach\PhpTypography\PhpTypography();
$prettyHtml = $typography->process($html);
echo $prettyHtml;

The above code will print (soft hyphens not shown)

<p>I’m waiting for “Peter”…</p>

By the way, if you’re using the full-stack Symfony framework and Twig, there is also the TypographyBundle which comes with nice little helpers such as the {% typography %} tag and the {{ text|typography }} filter.

Configuration

A thorough explanation of the configuration can be found at the KINGdesk homepage.

Hyphenation depends on the language, which can be set with set_hyphenation_language($languageCode). For example, to set the hyphenation language to French or German, call

$typography->set_hyphenation_language('fr'); // set to French
$typography->set_hyphenation_language('de'); // set to German

The default language is American English. Refer to the filenames in the lang/ directory for an overview of available languages.