"Typography" is an open source PHP software that automatically can format your text. It can place spaces and correct mechanical errors in the text, replace characters and brackets. This software can be useful for people who are engaged in the production and formatting of texts for public purposes, such as web pages, promotional materials, presentations, resumes, news, public posts, etc.
Using the "Typography" allows you to significantly reduce the time for correcting and formatting the text, since the service automatically processes all the necessary actions. In addition, "Typography" guarantees high accuracy and quality of correction, which helps to avoid punctuation errors.
This can be especially useful for professional writers, journalists, advertisers and other people whose work is related to text content.
- PHP 8.0 or higher
Install with composer:
composer require fater/typography
To run "Typography" with default formatting rules use this code example:
<?php
use Fater\Typography\Typography;
$formattedText = Typography::init()->apply('Your text');
echo $formattedText;
If you want to make special formatting rules you can make class from base rule template:
<?php
use Fater\Typography\Rules\Rule;
use Your\Namespace\Rules;
class YourOwnRule extends Rule
{
public function handle(string $text): string
{
// Your code modification rules
$text .= ' World!';
// Return formatted text
return $text;
}
}
Add your rule to the list of handlers to use it:
<?php
use Fater\Typography\Typography;
use Fater\Typography\TypographyRules;
use Your\Namespace\Rules\YourOwnRule;
$rules = TypographyRules::init()->addRules([YourOwnRule::class]);
// Text will be formatted with default list of rules including your rule
$formattedText = Typography::init($rules) // Set rules instance with your rule
->apply('Hello');
At the beginning clear all rules list, add your rule to the list of handlers to use it:
<?php
use Fater\Typography\Typography;
use Fater\Typography\TypographyRules;
$rules = TypographyRules::init()
->clearAll()
->addRules([YourOwnRule::class]);
// Text will be formatted only with your rule
$formattedText = Typography::init($rules) // Set rules instance with your rule
->apply('Hello');
echo $formattedText;
The above example will output:
Hello World!
- Space:
- Add space after comma
- Add space after dot (ignore domains) TODO: emails/IP
- Remove space before punctuation (.,:;?!)
- Remove space in each paragraph
- Remove redundant line breaks
- Characters:
- Replace special characters (c), (r), (tm), +-, ..., <-, ->
- Replace dash
- First letter in uppercase
Supports of formatting plain text and HTML code
Read Changelog in releases list to know all product changes.
License MIT, see more details in LICENSE