PHP Text Utilities
This librairy provides utilities function to ease text manipulation, (*1)
Install package with composer, (*3)
composer require hugsbrugs/php-text
In your PHP code, load library, (*4)
require_once __DIR__ . '/../vendor/autoload.php'; use Hug\Text\Text as Text;
Returns a random extract of a text, (*5)
Text::extract($text, $min_extract_length = 5, $max_extract_length = 10);
Removes non breaking spaces from a string, (*6)
Text::remove_non_breaking_spaces($text);
Cleans bad UTF-8 chars from text, (*7)
Text::clean_utf8($text);
Converts a text into UTF-8, (*8)
Text::convert_to_utf8($text);
Fixes curly brackets, (*9)
Text::fix_curly($text);
Fixes windows encoding, (*10)
Text::fix_windows_encoding($text);
Cleans a text from small sentences, (*11)
Text::remove_sentences($text, $min_phrase_words = 12, $separator = "\n");
Extract all emails contained in a text, (*12)
Text::extract_emails($text);
Extract first email found in a text, (*13)
Text::extract_first_email($text);
Get difference between two texts, (*14)
Text::diff($old, $new);
Get difference between two texts in HTML, (*15)
Text::html_diff($old, $new);
Guess most propable language from a text using PEAR DetectLanguage, (*16)
Text::get_lang($text, '2');
Get all available languages with PEAR DetectLanguage Library, (*17)
$test = Text::get_languages();
Remove UTF-8 BOM from text, (*18)
$text_without_bom = Text::remove_utf8_bom($text_with_bom);
Remove multiple spaces, tabs and line breaks from text, (*19)
$text_without_spaces = Text::remove_multiple_spaces($text_with_spaces);
Hugo Maugey Webmaster | Consultant SEO | Fullstack developer, (*20)