Text helper
1Presentation
Helper offering several methods of handling character strings.
2filenamize()
Converts text into a string that can be used as a file name.
Method signature:
filenamize(string $filename, bool $hyphenSpaces=true, bool $lowercase=true) : string
Parameters:
- $filename: Text to convert.
- $hyphenSpaces: true to replace spaces with dashes.
- $lowercase: true to make text all lowercase.
Return value: The file name.
3urlize()
Converts text so that it can be used in a URL.
Method signature:
urlize(?string $txt, bool $avoidUnderscores=true) : string
Parameters:
- $txt: Text to convert.
- $avoidUnderscores: true to replace underscores with dashes.
Return value: The converted text.
4isValidHtmlSyntax()
This method checks whether an HTML feed is syntactically correct.
Method signature:
isValidHtmlSyntax(string $html) : bool
Parameter: The HTML stream to be validated.
Return value: true if the HTML stream is valid, false otherwise.
5htmlToText()
This method transforms an HTML stream into plain text.
Method signature:
htmlToText(string $html, bool $cleanup=false) : string
Parameters:
- $html: HTML stream to convert.
- $cleanup: true to remove the content of <blockquote>, <pre> and <code> tags.
Return value: Plain text generated from HTML.
6encodingCompatible()
This method indicates whether a character string encoded in UTF-8 contains only characters compatible with the encoding supplied as a parameter.
Method signature:
encodingCompatible(string $text, string $encoding) : bool
Parameters:
- $text: The text to analyze.
- $encoding: The encoding to use.
Return value: Return value : True if the text contains only characters compatible with the character encoding supplied in parameter.
7ascii()
This method converts a string so that it contains only ASCII characters.
Method signature:
ascii(?string $text) : string
Parameters:
- $text : The text to be transformed.
Return value: The transformed text.
8firstChunk()
This method returns the part of a string before a separator.
Method signature:
firstChunk(string $str, string $separator) : string
Parameters:
- $str : The input string.
- $separator : The separator.
Return value: The part before the string, or an empty string if the separator was not found.
9lastChunk()
This method returns the part of a string after a separator.
Method signature:
lastChunk(string $str, string $separator) : string
Parameters:
- $str : The input string
- $separator : The separator.
Return value: The part after the string, or an empty string if the separator was not found.
10hasLower()
This method indicates whether a string contains a lowercase character.
Method signature:
hasLower(?string $txt) : bool
Parameters:
- $txt : The string to be analyzed.
Return value : true if the string contains a lowercase character. False otherwise.
11hasUpper()
This method indicates whether a string contains an uppercase character.
Method signature:
hasUpper(?string $txt) : bool
Parameters:
- $txt : The string to be analyzed.
Return value: true if the string contains an uppercase character. False otherwise.
12convertCase()
This method converts the writing style of a character string.
Method signature:
convertCase(?string $txt, string $inCase, string $outCase, ?bool $upperCase=null, bool $ascii=false) : ?string
Parameters:
- $txt : The string to convert.
- $inCase : The writing style of the input string. Can take the values \Temma\Utils\Text::SNAKE_CASE, \Temma\Utils\Text::KEBAB_CASE, \Temma\Utils\Text::CAMEL_CASE or \Temma\Utils\Text::PASCAL_CASE.
- $outCase : The writing style of the output string. Can take the values \Temma\Utils\Text::SNAKE_CASE, \Temma\Utils\Text::KEBAB_CASE, \Temma\Utils\Text::CAMEL_CASE or \Temma\Utils\Text::PASCAL_CASE.
- $upperCase : (optional) true for uppercase, false for lowercase, null for case insensitive.
- $ascii : true to convert the output string to contain only ASCII characters.
Return value: The converted string, or null if the input string was null.