WireTextTools class

Specific text and markup tools for ProcessWire $sanitizer and elsewhere.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireTextTools class also inherits all the methods and properties of: Wire.

Show class?             Show args?        

Common

NameReturnSummary 
collapse(string $str)
stringCollapse string to plain text that all exists on a single long line without destroying words/punctuation. 
diffMarkup(string $old, string $new)
stringGiven two strings ($old and $new) return a diff string in HTML markup 
findPlaceholders(string $str)
array boolFind and return all {placeholder} tags found in given string 
findReplaceEscapeChars($str, array $escapeChars)
arrayFind escaped characters in $str, replace them with a placeholder, and return the placeholders 
fixUnclosedTags(string $str)
stringRemove (or close) unclosed HTML tags from given string 
getPunctuationChars()
arrayGet array of punctuation characters 
getVisibleLength(string $str)
intReturn visible length of string, which is length not counting markup or entities 
getWordAlternates(string $word)
arrayGet alternate words for given word 
hasPlaceholders(string $str)
boolDoes the string have any {placeholder} tags in it? 
markupToText(string $str)
stringConvert HTML markup to readable text 
populatePlaceholders(string $str, $vars)
stringGiven a string ($str) and values ($vars), populate placeholder “{tags}” in the string with the values 
truncate(string $str, $maxLength)
stringTruncate string to given maximum length without breaking words 

For hooks

These methods are only useful for hooking and should not be called directly.

PHP function alternates

NameReturnSummary 
ltrim(string $str)
stringStrip whitespace (or other characters) from the beginning of string only (aka left trim) 
rtrim(string $str)
stringStrip whitespace (or other characters) from the end of string only (aka right trim) 
stripos(string $haystack, string $needle)
bool false intFind the position of the first occurrence of a case-insensitive substring in a string 
stristr(string $haystack, string $needle)
false stringFind the first occurrence of a string (case insensitive) 
strlen(string $str)
intGet string length 
strpos(string $haystack, string $needle)
bool false intFind position of first occurrence of string in a string 
strrchr(string $haystack, string $needle)
false stringFind the last occurrence of a character in a string 
strripos(string $haystack, string $needle)
bool false intFind the position of the last occurrence of a case-insensitive substring in a string 
strrpos(string $haystack, string $needle)
bool false intFind the position of the last occurrence of a substring in a string 
strstr(string $haystack, string $needle)
false stringFind the first occurrence of a string 
strtolower(string $str)
stringMake a string lowercase 
strtoupper(string $str)
stringMake a string uppercase 
substr(string $str, int $start)
stringGet part of a string 
substrCount(string $haystack, string $needle)
intCount the number of substring occurrences 
trim(string $str)
stringStrip whitespace (or other characters) from the beginning and end of a string 

Additional methods and properties

In addition to the methods and properties above, WireTextTools also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.244

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer