zigazou/french-typography

Apply french typography to an HTML string

Maintainers

Package info

github.com/Zigazou/french-typography

pkg:composer/zigazou/french-typography

Transparency log

Statistics

Installs: 43

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.13 2026-08-08 03:59 UTC

This package is not auto-updated.

Last update: 2026-08-22 04:15:50 UTC


README

FrenchTypography is a PHP module that automatically applies French typography rules to HTML code in UTF-8. This module improves the presentation and readability of texts by respecting the typographic standards in force in France.

Usage

<?php
require('vendor/autoload.php');

use Zigazou\FrenchTypography\Correcteur;

// This will return: Bonjour le monde « monde » !
$a = Correcteur::corriger('Bonjour le "monde"!');

// This will return: <div class="d">Bonjour le monde « monde » !</div>
$b = Correcteur::corriger('<div class="d">Bonjour le "monde"!</div>', TRUE);

Features

  • Adds a narrow no-break space before :, ;, !, and ?, and normalizes the following space.
  • Normalizes spacing around periods and commas, including at HTML block boundaries.
  • Converts English double quotes to French guillemets with narrow no-break spaces ("Hello"« Hello ») and straight apostrophes to typographic apostrophes.
  • Converts three dots to an ellipsis and normalizes repeated or mixed ! and ? punctuation.
  • Replaces common ASCII sequences with Unicode equivalents: arrows, copyright, registered, trademark, sound-recording copyright, warning, and emoticons.
  • Restores selected accents on initial capital letters and missing œ/Œ ligatures (for example, EconomieÉconomie and boeufbœuf).
  • Corrects the preposition A to À where appropriate.
  • Formats French phone numbers (099999999909 99 99 99 99).
  • Uses a no-break space between numbers and supported units or currencies, and narrow no-break spaces as thousands separators.
  • Converts ordinal suffixes to superscript HTML (1er1<sup>er</sup>).
  • Collapses consecutive spaces, preserves line breaks, and trims leading and trailing whitespace.
  • Supports HTML input without altering tags or URLs.

Installation

To install FrenchTypography, you can use Composer:

composer require zigazou/french-typography

Running tests

To run all the tests: vendor/bin/phpunit test