2017 © Pedro Peláez
 

library php-typography

The KINGdesk PHP Typography library improves typography on the web.

image

nystudio107/php-typography

The KINGdesk PHP Typography library improves typography on the web.

  • Monday, October 16, 2017
  • by khalwat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PhpTypography

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

Installation

Install PhpTypography with composer via, (*2)

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

and then use the class like, (*3)

$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., (*4)

Before After Explanation
explanation ex­pla­na­tion Robust hyphenation with soft hyphens ­. The browser will hyphenate words automatically based on the current line width. This is especially useful where the line width is rather small, for example in multi-column texts (CSS property column-count).
I'm waiting for "Peter" I’m waiting for “Peter” Use correct quotes and apostrophes
... Use the ellipses symbol
A flock of sparrows - some of them juveniles - alighted and sang. A flock of sparrows — some of them juveniles — alighted and sang. Use an em-dash instead of a hypen
14-20 men 14–20 men Use an en-dash instead of a hypen in ranges
Acme Corporation & Partners Acme Corporation <span class="amp">&</span> Partners Ampersands symbols are marked up so that you can choose a different font for them and make them look beatiful. Search the web for “ampersand font” as a start.

For more examples, see the project homepage., (*5)

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:, (*6)

$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), (*7)

<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., (*8)

Configuration

A thorough explanation of the configuration can be found at the KINGdesk homepage., (*9)

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, (*10)

$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., (*11)

The Versions

16/10 2017

dev-master

9999999-dev

The KINGdesk PHP Typography library improves typography on the web.

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.0

 

16/10 2017

dev-develop

dev-develop

The KINGdesk PHP Typography library improves typography on the web.

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.0

 

16/10 2017

1.0.0

1.0.0.0

The KINGdesk PHP Typography library improves typography on the web.

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3.0