Documentation

Utils
in package
uses BackwardCompatibility

Holds some widely used stuff, like $context and $smcFunc.

Table of Contents

Constants

ENT_LIST  = '&(?' . '>A(?' . '>acute|breve|grave|tilde|Elig|lpha' . '|macr|ring|scr|uml|fr|nd|c(?' . '>irc|y)|o(?' . '>gon|pf))|B(?' . '>rev' . 'e|arv|opf|scr|cy|fr|e(?' . '>cause|ta))|C(?' . '>ircle(?' . '>Times|Plu' . 's|Dot)|ross|Hcy|dot|scr|fr|hi|up(?' . '>Cap|)|a(?' . '>cute|p(?' . '>it' . 'alDifferentialD|))|c(?' . '>onint|aron|edil|irc)|e(?' . '>nterDot|dilla' . ')|o(?' . '>product|lon(?' . '>e|)|n(?' . '>tourIntegral|gruent)))|D(?' . '>Dotrahd|elta|Jcy|Scy|Zcy|fr|a(?' . '>gger|shv|rr)|c(?' . '>aron|y)|i(?' . '>fferentialD|acritical(?' . '>DoubleAcute|Acute|Tilde))|o(?' . '>tDot|u' . 'ble(?' . '>ContourIntegral|RightTee|UpArrow|Dot|L(?' . '>ongRightArrow|' . 'eftArrow))|pf|wn(?' . '>Arrow(?' . '>UpArrow|Bar)|Breve|Right(?' . '>Te' . 'eVector|VectorBar)|arrow|Left(?' . '>RightVector|TeeVector|VectorBar)|T' . 'ee(?' . '>Arrow|)))|s(?' . '>trok|cr))|E(?' . '>psilon|acute|grave|xist' . 's|qual|dot|sim|uml|NG|TH|fr|ta|c(?' . '>aron|irc|y)|m(?' . '>acr|pty(?' . '>VerySmallSquare|SmallSquare))|o(?' . '>gon|pf))|F(?' . '>illedSmallSqu' . 'are|cy|fr|o(?' . '>uriertrf|pf))|G(?' . '>reater(?' . '>Greater|Tilde)|' . 'breve|amma(?' . '>d|)|Jcy|dot|opf|scr|fr|c(?' . '>edil|irc|y)|g)|H(?' . '>ilbertSpace|umpEqual|ARDcy|strok|circ|fr|a(?' . '>cek|t)|o(?' . '>rizo' . 'ntalLine|pf))|I(?' . '>acute|grave|tilde|Jlig|Ecy|Ocy|dot|fr|c(?' . '>i' . 'rc|y)|m(?' . '>plies|a(?' . '>ginaryI|cr))|n(?' . '>visibleTimes|t(?' . '>egral|))|o(?' . '>gon|pf|ta)|u(?' . '>kcy|ml))|J(?' . '>ukcy|opf|fr|c(' . '?' . '>irc|y)|s(?' . '>ercy|cr))|K(?' . '>appa|Hcy|Jcy|opf|scr|fr|c(?' . '>edil|y))|L(?' . '>midot|Jcy|fr|a(?' . '>cute|mbda|ng|rr)|c(?' . '>aron' . '|edil|y)|e(?' . '>ft(?' . '>RightVector|VectorBar|ArrowBar|Floor|Do(?' . '>ubleBracket|wn(?' . '>TeeVector|VectorBar))|Up(?' . '>DownVector|TeeVe' . 'ctor|VectorBar)|T(?' . '>riangle(?' . '>Equal|Bar)|ee(?' . '>Vector|Arr' . 'ow)))|ss(?' . '>Tilde|Less))|l|o(?' . '>werRightArrow|ng(?' . '>LeftRig' . 'htArrow|RightArrow)|pf)|s(?' . '>trok|h))|M(?' . '>inusPlus|opf|ap|cy|f' . 'r|e(?' . '>diumSpace|llintrf)|u)|N(?' . '>ewLine|acute|tilde|Jcy|scr|fr' . '|c(?' . '>aron|edil|y)|o(?' . '>Break|t(?' . '>RightTriangle(?' . '>Equ' . 'al|Bar)|Precedes(?' . '>SlantEqual|Equal)|Greater(?' . '>FullEqual|Grea' . 'ter|Less)|Nested(?' . '>GreaterGreater|LessLess)|Equal|Tilde|Le(?' . '>' . 'ftTriangleBar|ss(?' . '>Equal|))|C(?' . '>ongruent|upCap)|S(?' . '>quar' . 'eSu(?' . '>perset(?' . '>Equal|)|bset(?' . '>Equal|))|u(?' . '>persetEq' . 'ual|bsetEqual|cceeds(?' . '>SlantEqual|Equal|Tilde|)))|))|u)|O(?' . '>p' . 'enCurly(?' . '>DoubleQuote|Quote)|acute|dblac|grave|Elig|opf|uml|ver(?' . '>Parenthesis|Brac(?' . '>ket|e))|fr|ti(?' . '>lde|mes)|c(?' . '>irc|y)|' . 'm(?' . '>icron|acr|ega)|r|s(?' . '>lash|cr))|P(?' . '>cy|fr|hi|i|r(?' . '>ecedesSlantEqual|ime|)|s(?' . '>cr|i))|Q(?' . '>scr|fr)|R(?' . '>uleDe' . 'layed|everse(?' . '>UpEquilibrium|Element)|ight(?' . '>VectorBar|Ceilin' . 'g|Floor|Do(?' . '>ubleBracket|wn(?' . '>TeeVector|Vector(?' . '>Bar|)))' . '|Up(?' . '>DownVector|TeeVector|Vector(?' . '>Bar|))|A(?' . '>ngleBrack' . 'et|rrowBar)|T(?' . '>eeVector|riangle(?' . '>Equal|Bar)))|fr|ho|a(?' . '>cute|rrtl|ng)|c(?' . '>aron|edil|y)|o(?' . '>undImplies|pf))|S(?' . '>' . 'OFTcy|acute|igma|opf|scr|tar|fr|H(?' . '>CHcy|cy)|c(?' . '>aron|edil|ir' . 'c|y|)|q(?' . '>uare(?' . '>Su(?' . '>persetEqual|bsetEqual)|)|rt)|u(?' . '>cceeds(?' . '>Equal|Tilde)|pset|b(?' . '>setEqual|)))|T(?' . '>ildeFul' . 'lEqual|ripleDot|HORN|opf|fr|S(?' . '>Hcy|cy)|a(?' . '>b|u)|c(?' . '>aro' . 'n|edil|y)|h(?' . '>eta|i(?' . '>ckSpace|nSpace))|s(?' . '>trok|cr))|U(?' . '>dblac|grave|tilde|macr|ring|scr|uml|br(?' . '>eve|cy)|fr|a(?' . '>cute' . '|rr(?' . '>ocir|))|c(?' . '>irc|y)|n(?' . '>ionPlus|der(?' . '>Parenthe' . 'sis|Brace))|o(?' . '>gon|pf)|p(?' . '>perRightArrow|DownArrow|downarrow' . '|ArrowBar|TeeArrow|silon))|V(?' . '>vdash|Dash|dash(?' . '>l|)|bar|opf|' . 'scr|cy|er(?' . '>ticalSeparator|bar)|fr)|W(?' . '>circ|opf|scr|fr)|X(?' . '>opf|scr|fr|i)|Y(?' . '>acute|Acy|Icy|Ucy|opf|scr|uml|fr|c(?' . '>irc|y' . '))|Z(?' . '>acute|Hcy|dot|opf|scr|fr|c(?' . '>aron|y)|e(?' . '>roWidthS' . 'pace|ta))|a(?' . '>acute|breve|grave|tilde|elig|ring|uml|c(?' . '>irc|E' . '|d|y|)|f(?' . '>r|)|l(?' . '>eph|pha)|m(?' . '>a(?' . '>cr|lg)|p)|n(?' . '>d(?' . '>slope|and|d|v|)|g(?' . '>zarr|msd(?' . '>a(?' . '>a|b|c|d|e|f' . '|g|h)|)|sph|le|rt(?' . '>vb(?' . '>d|)|)|e))|o(?' . '>gon|pf)|p(?' . '>' . 'acir|prox|id|os|E|e)|s(?' . '>cr|t)|w(?' . '>conint|int))|b(?' . '>karo' . 'w|rvbar|dquo|Not|brk(?' . '>tbrk|)|fr|ig(?' . '>triangle(?' . '>down|up' . ')|sqcup|uplus|c(?' . '>irc|ap|up)|o(?' . '>times|plus))|a(?' . '>ck(?' . '>epsilon|prime|simeq)|r(?' . '>vee|wed))|c(?' . '>ong|y)|e(?' . '>mptyv' . '|t(?' . '>ween|a|h))|l(?' . '>ock|a(?' . '>cktriangle(?' . '>right|down' . '|left|)|nk)|k(?' . '>34|1(?' . '>2|4)))|n(?' . '>ot|e(?' . '>quiv|))|o(' . '?' . '>wtie|pf|x(?' . '>minus|plus|box|D(?' . '>L|R|l|r)|H(?' . '>D|U|d' . '|u|)|U(?' . '>L|R|l|r)|V(?' . '>H|L|R|h|l|r|)|d(?' . '>L|R|l|r)|h(?' . '>D|U|d|u)|u(?' . '>L|R|l|r)|v(?' . '>H|L|R|h|l|r|)))|s(?' . '>emi|cr|im' . '|ol(?' . '>hsub|b|))|u(?' . '>ll|mp(?' . '>E|)))|c(?' . '>ylcty|lubs|td' . 'ot|dot|fr|ir(?' . '>fnint|scir|mid|E|c(?' . '>eq|)|)|a(?' . '>cute|ret|' . 'p(?' . '>brcup|and|dot|c(?' . '>ap|up)|s|))|c(?' . '>edil|irc|ups(?' . '>sm|)|a(?' . '>ron|ps))|e(?' . '>mptyv|nt)|h(?' . '>eck|cy|i)|o(?' . '>' . 'ngdot|lon(?' . '>eq|)|m(?' . '>ma(?' . '>t|)|p(?' . '>lexes|fn|))|p(?' . '>f|y(?' . '>sr|)))|r(?' . '>arr|oss)|s(?' . '>cr|u(?' . '>b(?' . '>e|)|' . 'p(?' . '>e|)))|u(?' . '>larrp|darr(?' . '>l|r)|esc|p(?' . '>brcap|dot|o' . 'r|c(?' . '>ap|up)|s|)|r(?' . '>vearrowleft|arr(?' . '>m|)|ren|ly(?' . '>eqprec|wedge|vee)))|w(?' . '>conint|int))|d(?' . '>bkarow|dotseq|wangl' . 'e|lcrop|harl|tdot|Har|jcy|a(?' . '>gger|leth|shv|rr)|c(?' . '>aron|y)|e' . '(?' . '>mptyv|lta|g)|f(?' . '>isht|r)|i(?' . '>amond(?' . '>suit|)|sin|' . 'v(?' . '>ide|onx))|o(?' . '>ublebarwedge|wndownarrows|llar|pf|t(?' . '>' . 'eqdot|))|r(?' . '>bkarow|c(?' . '>orn|rop))|s(?' . '>trok|ol|c(?' . '>r' . '|y))|z(?' . '>igrarr|cy))|e(?' . '>rarr|dot|fr|a(?' . '>cute|ster)|c(?' . '>aron|ir(?' . '>c|)|y)|g(?' . '>rave|s(?' . '>dot|)|)|l(?' . '>inters|l' . '|s(?' . '>dot|)|)|m(?' . '>acr|pty|sp(?' . '>1(?' . '>3|4)|))|n(?' . '>' . 'sp|g)|o(?' . '>gon|pf)|p(?' . '>lus|ar(?' . '>sl|)|si)|q(?' . '>vparsl|' . 'colon|u(?' . '>ivDD|als|est))|s(?' . '>dot|cr|im)|t(?' . '>a|h)|u(?' . '>ml|ro)|x(?' . '>cl|p(?' . '>onentiale|ectation)))|f(?' . '>allingdotse' . 'q|partint|emale|ilig|jlig|nof|scr|cy|f(?' . '>ilig|l(?' . '>lig|ig)|r)|' . 'l(?' . '>lig|tns|at)|o(?' . '>pf|r(?' . '>all|kv))|r(?' . '>own|a(?' . '>sl|c(?' . '>45|78|1(?' . '>3|4|5|6|8)|2(?' . '>3|5)|3(?' . '>4|5|8)|5(' . '?' . '>6|8)))))|g(?' . '>vertneqq|breve|imel|rave|dot|jcy|opf|El|fr|a(?' . '>cute|mma(?' . '>d|)|p)|c(?' . '>irc|y)|e(?' . '>qq|s(?' . '>dot(?' . '>o(?' . '>l|)|)|cc|l(?' . '>es|)|)|)|g|l(?' . '>E|a|j|)|n(?' . '>sim|ap' . '|e(?' . '>qq|))|s(?' . '>cr|im(?' . '>e|l))|t(?' . '>quest|lPar|c(?' . '>ir|c)|r(?' . '>eqless|arr|dot)|))|h(?' . '>circ|Arr|fr|a(?' . '>irsp|l' . 'f|r(?' . '>dcy|r(?' . '>cir|w|)))|e(?' . '>arts|llip|rcon)|o(?' . '>mth' . 't|rbar|arr|pf)|s(?' . '>trok|cr)|y(?' . '>bull|phen))|i(?' . '>acute|gr' . 'ave|quest|tilde|jlig|prod|fr|c(?' . '>irc|y|)|e(?' . '>xcl|cy)|i(?' . '>iint|nfin|ota)|m(?' . '>ped|of|a(?' . '>gline|cr))|n(?' . '>care|odot|' . 'fin(?' . '>tie|)|t(?' . '>larhk|cal))|o(?' . '>gon|cy|pf|ta)|s(?' . '>c' . 'r|in(?' . '>dot|E|s(?' . '>v|)|v))|u(?' . '>kcy|ml))|j(?' . '>math|ukcy' . '|opf|fr|c(?' . '>irc|y)|s(?' . '>ercy|cr))|k(?' . '>green|appa|hcy|jcy|' . 'opf|scr|fr|c(?' . '>edil|y))|l(?' . '>vertneqq|Barr|Har|jcy|par(?' . '>' . 'lt|)|gE|ur(?' . '>dshar|uhar)|A(?' . '>tail|arr)|E|a(?' . '>emptyv|cute' . '|gran|mbda|quo|ng(?' . '>le|d)|rr(?' . '>bfs|sim|fs|hk|lp|pl|tl|)|p|t(?' . '>ail|e(?' . '>s|)|))|b(?' . '>arr|brk|r(?' . '>ac(?' . '>e|k)|k(?' . '>' . 'sl(?' . '>d|u)|e)))|c(?' . '>aron|e(?' . '>dil|il)|y)|d(?' . '>ca|sh|r(' . '?' . '>ushar|dhar))|e(?' . '>ft(?' . '>rightharpoons|harpoon(?' . '>dow' . 'n|up))|q|s(?' . '>dot(?' . '>o(?' . '>r|)|)|cc|g(?' . '>es|)|s(?' . '>d' . 'ot|gtr|eq(?' . '>qgtr|gtr))|))|f(?' . '>isht|r)|h(?' . '>arul|blk)|l(?' . '>corner|hard|arr|tri|)|m(?' . '>idot|oust)|n(?' . '>sim|ap|e(?' . '>qq|' . '))|o(?' . '>oparrowright|ngleftarrow|times|a(?' . '>ng|rr)|p(?' . '>lus' . '|ar|f)|w(?' . '>ast|bar)|z(?' . '>enge|f))|r(?' . '>hard|arr|tri|m)|s(?' . '>aquo|trok|cr|im(?' . '>e|g))|t(?' . '>quest|hree|imes|larr|c(?' . '>ir' . '|c)|r(?' . '>Par|i)|))|m(?' . '>DDot|dash|lcp|scr|fr|ho|a(?' . '>rker|c' . 'r|l(?' . '>tese|e)|p)|c(?' . '>omma|y)|i(?' . '>cro|nus(?' . '>d(?' . '>u|)|)|d(?' . '>cir|))|o(?' . '>dels|pf)|u(?' . '>map|))|n(?' . '>dash|' . 'jcy|fr|is(?' . '>d|)|G(?' . '>g|t)|L(?' . '>eftarrow|l|t(?' . '>v|))|V(' . '?' . '>Dash|dash)|a(?' . '>cute|bla|tur(?' . '>als|)|ng|p(?' . '>prox|i' . 'd|os|E))|b(?' . '>ump(?' . '>e|)|sp)|c(?' . '>edil|ong(?' . '>dot|)|up|' . 'a(?' . '>ron|p)|y)|e(?' . '>arhk|xist|Arr|dot|sim)|g(?' . '>sim|tr|e(?' . '>q|s))|h(?' . '>Arr|par)|l(?' . '>sim|tri(?' . '>e|)|dr|E|e(?' . '>ft(?' . '>rightarrow|arrow)|s))|o(?' . '>pf|t(?' . '>niv(?' . '>a|b|c)|in(?' . '>dot|E|v(?' . '>b|c)|)|))|p(?' . '>olint|ar(?' . '>allel|sl|t)|r)|r(?' . '>Arr|arr(?' . '>c|w|))|s(?' . '>hortmid|ime|cr|u(?' . '>b(?' . '>E|)|p(' . '?' . '>set(?' . '>eqq|)|)))|t(?' . '>riangleright|ilde|lg)|u(?' . '>m(?' . '>ero|sp|)|)|v(?' . '>infin|Dash|Harr|dash|sim|ap|g(?' . '>e|t)|l(?' . '>Arr|e|t(?' . '>rie|))|r(?' . '>trie|Arr))|w(?' . '>near|Arr|ar(?' . '>' . 'row|hk)))|o(?' . '>elig|hbar|vbar|opf|uml|ti(?' . '>mesas|lde)|S|a(?' . '>cute|st)|c(?' . '>ir(?' . '>c|)|y)|d(?' . '>blac|sold|ash|iv)|f(?' . '>cir|r)|g(?' . '>rave|on|t)|l(?' . '>arr|ine|c(?' . '>ross|ir)|t)|m(?' . '>acr|ega|i(?' . '>cron|nus|d))|p(?' . '>erp|ar)|r(?' . '>slope|igof|arr' . '|or|d(?' . '>erof|f|m|)|v|)|s(?' . '>lash|ol))|p(?' . '>uncsp|ar(?' . '>a|s(?' . '>im|l)|t)|cy|er(?' . '>tenk|cnt|iod|mil|p)|fr|h(?' . '>one|i' . ')|i(?' . '>tchfork|v|)|l(?' . '>anck(?' . '>h|)|us(?' . '>acir|cir|sim|' . 'two|mn|d(?' . '>o|u)|e|))|o(?' . '>intint|und|pf)|r(?' . '>urel|ime(?' . '>s|)|ec(?' . '>approx|sim|eq|n(?' . '>approx|eqq|sim)|)|E|o(?' . '>d|f(' . '?' . '>alar|line|surf)|p))|s(?' . '>cr|i))|q(?' . '>prime|opf|scr|fr|u(' . '?' . '>atint|est|ot))|r(?' . '>uluhar|moust|nmid|rarr|Har|lm|A(?' . '>t' . 'ail|arr)|a(?' . '>emptyv|quo|ng(?' . '>d|e)|rr(?' . '>bfs|sim|ap|fs|hk|' . 'pl|tl|c|w)|c(?' . '>ute|e)|t(?' . '>ail|io(?' . '>nals|)))|b(?' . '>brk' . '|rk(?' . '>sl(?' . '>d|u)|e))|c(?' . '>aron|edil|ub|y)|d(?' . '>ldhar|q' . 'uo|ca|sh)|e(?' . '>aline|ct|g)|f(?' . '>isht|r)|h(?' . '>ar(?' . '>d|u(' . '?' . '>l|))|o(?' . '>v|))|i(?' . '>singdotseq|ghtleft(?' . '>harpoons|a' . 'rrows)|ng)|o(?' . '>times|a(?' . '>ng|rr)|p(?' . '>lus|ar|f))|p(?' . '>' . 'polint|ar(?' . '>gt|))|s(?' . '>aquo|cr|h|q(?' . '>uo|b))|t(?' . '>hree' . '|imes|ri(?' . '>ltri|))|x)|s(?' . '>padesuit|acute|bquo|rarr|zlig|dot(?' . '>b|e|)|fr|c(?' . '>polint|aron|edil|irc|E|n(?' . '>sim|E)|y)|e(?' . '>a' . 'rhk|swar|Arr|ct|mi|xt)|h(?' . '>ortparallel|arp|c(?' . '>hcy|y)|y)|i(?' . '>gma(?' . '>v|)|m(?' . '>plus|rarr|dot|eq|ne|g(?' . '>E|)|l(?' . '>E|)|' . '))|m(?' . '>eparsl|ashp|ile|t(?' . '>e(?' . '>s|)|))|o(?' . '>ftcy|pf|l' . '(?' . '>b(?' . '>ar|)|))|q(?' . '>uarf|su(?' . '>pset|b)|c(?' . '>ap(?' . '>s|)|up(?' . '>s|)))|s(?' . '>etmn|cr)|t(?' . '>raight(?' . '>epsilon|p' . 'hi)|ar(?' . '>f|))|u(?' . '>cc(?' . '>curlyeq|napprox|approx|)|ng|b(?' . '>edot|mult|plus|rarr|dot|E|s(?' . '>etneq(?' . '>q|)|im|u(?' . '>b|p))|' . ')|m|p(?' . '>larr|mult|plus|hs(?' . '>ol|ub)|nE|1|2|3|d(?' . '>sub|ot)|' . 'e(?' . '>dot|)|s(?' . '>et(?' . '>eqq|neq)|im|u(?' . '>b|p))|))|w(?' . '>nwar|Arr|ar(?' . '>hk|r)))|t(?' . '>woheadrightarrow|elrec|prime|fr|a(' . '?' . '>rget|u)|c(?' . '>aron|edil|y)|h(?' . '>orn|e(?' . '>re4|ta(?' . '>sym|)))|i(?' . '>mes(?' . '>b(?' . '>ar|)|d|)|nt)|o(?' . '>ea|p(?' . '>bot|cir|f(?' . '>ork|)))|r(?' . '>pezium|ade|i(?' . '>angle(?' . '>dow' . 'n|q|)|minus|plus|time|dot|sb))|s(?' . '>trok|hcy|c(?' . '>r|y)))|u(?' . '>wangle|grave|macr|Har|scr|uml|br(?' . '>eve|cy)|a(?' . '>cute|rr)|c(?' . '>irc|y)|d(?' . '>blac|arr|har)|f(?' . '>isht|r)|h(?' . '>arl|blk)|l(?' . '>tri|c(?' . '>orner|rop))|o(?' . '>gon|pf)|p(?' . '>uparrows|si(?' . '>' . 'h|))|r(?' . '>ing|tri|c(?' . '>orner|rop))|t(?' . '>ilde|dot))|v(?' . '>zigzag|dash|nsub|rtri|Bar(?' . '>v|)|opf|cy|fr|a(?' . '>ngrt|r(?' . '>' . 'triangleleft|supsetneqq|kappa))|e(?' . '>llip|rt|e(?' . '>bar|eq))|s(?' . '>cr|u(?' . '>pne|bn(?' . '>E|e))))|w(?' . '>circ|opf|scr|ed(?' . '>bar|' . 'geq)|fr|p|r)|x(?' . '>wedge|hArr|lArr|map|nis|scr|vee|fr|i|o(?' . '>dot' . '|pf))|y(?' . '>icy|opf|scr|ac(?' . '>ute|y)|en|fr|c(?' . '>irc|y)|u(?' . '>cy|ml))|z(?' . '>igrarr|acute|dot|eta|hcy|opf|scr|fr|c(?' . '>aron|y)|' . 'w(?' . '>nj|j))|#(?' . '>\d+|x[0-9a-fA-F]+));'
Regular expression to match all named HTML entities and numeric entities.
ENT_NBSP  = '&(?' . '>nbsp|#(?' . '>x0*A0|0*160));'
Regular expression to match all forms of the non-breaking space entity.
TAB_SUBSTITUTE  = "​    ​"

Properties

$context  : array<string|int, mixed>
$smcFunc  : array<string|int, mixed>
$backcompat  : array<string|int, mixed>

Methods

adjustHeadingLevels()  : mixed
Adjusts the heading levels of h1-h6 elements in a string in order to fit the needs of a particular location in the output HTML.
arrayLength()  : int
Gets the total byte length of all leaf nodes in an array.
buildRegex()  : string|array<string|int, mixed>
Creates optimized regular expressions from arrays of strings.
casefold()  : string
Convenience alias of Utils::convertCase($string, 'fold')
checkMimeType()  : int
Checks whether a file or data has the expected MIME type.
cleanXml()  : string
Clean up the XML to make sure it doesn't contain invalid characters.
convertCase()  : string
Performs case conversion on UTF-8 strings.
emitFile()  : void
Emits a file for download. Mostly used for attachments.
entityDecode()  : string
Decodes and sanitizes HTML entities.
entityFix()  : string
Fixes double-encoded entities in a string.
entityStrlen()  : int
Like standard mb_strlen(), except that it counts HTML entities as single characters. This essentially amounts to getting the length of the string as it would appear to a human reader.
entityStrpos()  : int|false
Like standard mb_strpos(), except that it counts HTML entities as single characters.
entityStrSplit()  : array<string|int, mixed>
Like standard mb_str_split(), except that it counts HTML entities as single characters.
entitySubstr()  : string
Like standard mb_substr(), except that it counts HTML entities as single characters.
escapeJavaScript()  : string
Escapes (replaces) characters in strings to make them safe for use in JavaScript
escapestringRecursive()  : array<string|int, mixed>|string
Recursively applies database string escaping to all elements of an array.
exportStatic()  : void
Provides a way to export a class's public static properties and methods to global namespace.
extractWords()  : array<string|int, mixed>
Extracts all the words in a string.
fixUtf8mb4()  : string
Converts four-byte Unicode characters to entities, but only if the database can't handle four-byte characters natively.
getCallable()  : callable|false
Parses the given input to determine if it represents a callable entity.
getMimeType()  : string|false
Attempts to determine the MIME type of some data or a file.
htmlspecialchars()  : string
Wrapper for standard htmlspecialchars() that ensures the output respects the database's support (or lack thereof) for four-byte UTF-8 characters.
htmlspecialcharsDecode()  : string|false
Replaces special entities in strings with the real characters.
htmlspecialcharsRecursive()  : array<string|int, mixed>|string
Recursively applies self::htmlspecialchars() to all elements of an array.
htmlTrim()  : string|false
Like standard trim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.
htmlTrimLeft()  : string|false
Like standard ltrim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.
htmlTrimRecursive()  : array<string|int, mixed>|string|false
Recursively applies self::htmlTrim to all elements of an array.
htmlTrimRight()  : string|false
Like standard rtrim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.
jsonDecode()  : mixed
Wrapper function for json_decode() with error handling.
jsonEncode()  : string|false
Wrapper function for json_encode().
load()  : void
(Re)initializes some $context values that need to be set dynamically.
makeWritable()  : bool
Tries different modes to make files or directories writable.
normalize()  : string
Performs Unicode normalization on a UTF-8 string.
normalizeSpaces()  : string|false
Normalizes space characters and line breaks.
obExit()  : void
Ends execution. Takes care of template loading and remembering the previous URL.
randomBytes()  : string
Wrapper for random_bytes() that sets a default length.
randomInt()  : int
Wrapper for random_int() that sets default values.
redirectexit()  : void
Make sure the browser doesn't come back and repost the form data.
safeSerialize()  : string
Safe serialize() replacement.
safeUnserialize()  : mixed
Safe unserialize() replacement
sanitizeChars()  : string|false
Replaces invalid characters with a substitute.
sanitizeEntities()  : string
Replaces HTML entities for invalid characters with a substitute.
semanticSplit()  : array<string|int, mixed>
Splits a string into its words, symbols, punctuation, and whitespace.
sendHttpStatus()  : void
Sends an appropriate HTTP status header based on a given status code.
serverResponse()  : bool|void
Outputs a response.
shorten()  : string
Like Utils::entitySubstr(), except that this also appends an ellipsis to the returned string to indicate that it was truncated (unless it wasn't truncated because it was already short enough).
stripslashesRecursive()  : array<string|int, mixed>|string
Recursively applies stripslashes() to all elements of an array.
strtolower()  : string
Convenience alias of Utils::convertCase($string, 'lower')
strtotitle()  : string
Convenience alias of Utils::convertCase($string, 'title')
strtoupper()  : string
Convenience alias of Utils::convertCase($string, 'upper')
truncate()  : string|false
Truncates a string to fit within the specified byte length, while making sure not to cut in the middle of an HTML entity or multi-byte character.
truncateArray()  : array<string|int, mixed>
Truncates the leaf nodes of an array so that their cumulative byte length fits within a specified maximum.
ucfirst()  : string
Convenience alias of Utils::convertCase($string, 'ucfirst')
ucwords()  : string
Convenience alias of Utils::convertCase($string, 'ucwords')
unescapestringRecursive()  : array<string|int, mixed>|string
Recursively removes database string escaping in all elements of an array.
urldecodeRecursive()  : array<string|int, mixed>|string
Recursively applies urldecode() to all elements of an array.
loadFile()  : string|false
Helper method for Utils::call_helper.

Constants

ENT_LIST

Regular expression to match all named HTML entities and numeric entities.

public mixed ENT_LIST = '&(?' . '>A(?' . '>acute|breve|grave|tilde|Elig|lpha' . '|macr|ring|scr|uml|fr|nd|c(?' . '>irc|y)|o(?' . '>gon|pf))|B(?' . '>rev' . 'e|arv|opf|scr|cy|fr|e(?' . '>cause|ta))|C(?' . '>ircle(?' . '>Times|Plu' . 's|Dot)|ross|Hcy|dot|scr|fr|hi|up(?' . '>Cap|)|a(?' . '>cute|p(?' . '>it' . 'alDifferentialD|))|c(?' . '>onint|aron|edil|irc)|e(?' . '>nterDot|dilla' . ')|o(?' . '>product|lon(?' . '>e|)|n(?' . '>tourIntegral|gruent)))|D(?' . '>Dotrahd|elta|Jcy|Scy|Zcy|fr|a(?' . '>gger|shv|rr)|c(?' . '>aron|y)|i(?' . '>fferentialD|acritical(?' . '>DoubleAcute|Acute|Tilde))|o(?' . '>tDot|u' . 'ble(?' . '>ContourIntegral|RightTee|UpArrow|Dot|L(?' . '>ongRightArrow|' . 'eftArrow))|pf|wn(?' . '>Arrow(?' . '>UpArrow|Bar)|Breve|Right(?' . '>Te' . 'eVector|VectorBar)|arrow|Left(?' . '>RightVector|TeeVector|VectorBar)|T' . 'ee(?' . '>Arrow|)))|s(?' . '>trok|cr))|E(?' . '>psilon|acute|grave|xist' . 's|qual|dot|sim|uml|NG|TH|fr|ta|c(?' . '>aron|irc|y)|m(?' . '>acr|pty(?' . '>VerySmallSquare|SmallSquare))|o(?' . '>gon|pf))|F(?' . '>illedSmallSqu' . 'are|cy|fr|o(?' . '>uriertrf|pf))|G(?' . '>reater(?' . '>Greater|Tilde)|' . 'breve|amma(?' . '>d|)|Jcy|dot|opf|scr|fr|c(?' . '>edil|irc|y)|g)|H(?' . '>ilbertSpace|umpEqual|ARDcy|strok|circ|fr|a(?' . '>cek|t)|o(?' . '>rizo' . 'ntalLine|pf))|I(?' . '>acute|grave|tilde|Jlig|Ecy|Ocy|dot|fr|c(?' . '>i' . 'rc|y)|m(?' . '>plies|a(?' . '>ginaryI|cr))|n(?' . '>visibleTimes|t(?' . '>egral|))|o(?' . '>gon|pf|ta)|u(?' . '>kcy|ml))|J(?' . '>ukcy|opf|fr|c(' . '?' . '>irc|y)|s(?' . '>ercy|cr))|K(?' . '>appa|Hcy|Jcy|opf|scr|fr|c(?' . '>edil|y))|L(?' . '>midot|Jcy|fr|a(?' . '>cute|mbda|ng|rr)|c(?' . '>aron' . '|edil|y)|e(?' . '>ft(?' . '>RightVector|VectorBar|ArrowBar|Floor|Do(?' . '>ubleBracket|wn(?' . '>TeeVector|VectorBar))|Up(?' . '>DownVector|TeeVe' . 'ctor|VectorBar)|T(?' . '>riangle(?' . '>Equal|Bar)|ee(?' . '>Vector|Arr' . 'ow)))|ss(?' . '>Tilde|Less))|l|o(?' . '>werRightArrow|ng(?' . '>LeftRig' . 'htArrow|RightArrow)|pf)|s(?' . '>trok|h))|M(?' . '>inusPlus|opf|ap|cy|f' . 'r|e(?' . '>diumSpace|llintrf)|u)|N(?' . '>ewLine|acute|tilde|Jcy|scr|fr' . '|c(?' . '>aron|edil|y)|o(?' . '>Break|t(?' . '>RightTriangle(?' . '>Equ' . 'al|Bar)|Precedes(?' . '>SlantEqual|Equal)|Greater(?' . '>FullEqual|Grea' . 'ter|Less)|Nested(?' . '>GreaterGreater|LessLess)|Equal|Tilde|Le(?' . '>' . 'ftTriangleBar|ss(?' . '>Equal|))|C(?' . '>ongruent|upCap)|S(?' . '>quar' . 'eSu(?' . '>perset(?' . '>Equal|)|bset(?' . '>Equal|))|u(?' . '>persetEq' . 'ual|bsetEqual|cceeds(?' . '>SlantEqual|Equal|Tilde|)))|))|u)|O(?' . '>p' . 'enCurly(?' . '>DoubleQuote|Quote)|acute|dblac|grave|Elig|opf|uml|ver(?' . '>Parenthesis|Brac(?' . '>ket|e))|fr|ti(?' . '>lde|mes)|c(?' . '>irc|y)|' . 'm(?' . '>icron|acr|ega)|r|s(?' . '>lash|cr))|P(?' . '>cy|fr|hi|i|r(?' . '>ecedesSlantEqual|ime|)|s(?' . '>cr|i))|Q(?' . '>scr|fr)|R(?' . '>uleDe' . 'layed|everse(?' . '>UpEquilibrium|Element)|ight(?' . '>VectorBar|Ceilin' . 'g|Floor|Do(?' . '>ubleBracket|wn(?' . '>TeeVector|Vector(?' . '>Bar|)))' . '|Up(?' . '>DownVector|TeeVector|Vector(?' . '>Bar|))|A(?' . '>ngleBrack' . 'et|rrowBar)|T(?' . '>eeVector|riangle(?' . '>Equal|Bar)))|fr|ho|a(?' . '>cute|rrtl|ng)|c(?' . '>aron|edil|y)|o(?' . '>undImplies|pf))|S(?' . '>' . 'OFTcy|acute|igma|opf|scr|tar|fr|H(?' . '>CHcy|cy)|c(?' . '>aron|edil|ir' . 'c|y|)|q(?' . '>uare(?' . '>Su(?' . '>persetEqual|bsetEqual)|)|rt)|u(?' . '>cceeds(?' . '>Equal|Tilde)|pset|b(?' . '>setEqual|)))|T(?' . '>ildeFul' . 'lEqual|ripleDot|HORN|opf|fr|S(?' . '>Hcy|cy)|a(?' . '>b|u)|c(?' . '>aro' . 'n|edil|y)|h(?' . '>eta|i(?' . '>ckSpace|nSpace))|s(?' . '>trok|cr))|U(?' . '>dblac|grave|tilde|macr|ring|scr|uml|br(?' . '>eve|cy)|fr|a(?' . '>cute' . '|rr(?' . '>ocir|))|c(?' . '>irc|y)|n(?' . '>ionPlus|der(?' . '>Parenthe' . 'sis|Brace))|o(?' . '>gon|pf)|p(?' . '>perRightArrow|DownArrow|downarrow' . '|ArrowBar|TeeArrow|silon))|V(?' . '>vdash|Dash|dash(?' . '>l|)|bar|opf|' . 'scr|cy|er(?' . '>ticalSeparator|bar)|fr)|W(?' . '>circ|opf|scr|fr)|X(?' . '>opf|scr|fr|i)|Y(?' . '>acute|Acy|Icy|Ucy|opf|scr|uml|fr|c(?' . '>irc|y' . '))|Z(?' . '>acute|Hcy|dot|opf|scr|fr|c(?' . '>aron|y)|e(?' . '>roWidthS' . 'pace|ta))|a(?' . '>acute|breve|grave|tilde|elig|ring|uml|c(?' . '>irc|E' . '|d|y|)|f(?' . '>r|)|l(?' . '>eph|pha)|m(?' . '>a(?' . '>cr|lg)|p)|n(?' . '>d(?' . '>slope|and|d|v|)|g(?' . '>zarr|msd(?' . '>a(?' . '>a|b|c|d|e|f' . '|g|h)|)|sph|le|rt(?' . '>vb(?' . '>d|)|)|e))|o(?' . '>gon|pf)|p(?' . '>' . 'acir|prox|id|os|E|e)|s(?' . '>cr|t)|w(?' . '>conint|int))|b(?' . '>karo' . 'w|rvbar|dquo|Not|brk(?' . '>tbrk|)|fr|ig(?' . '>triangle(?' . '>down|up' . ')|sqcup|uplus|c(?' . '>irc|ap|up)|o(?' . '>times|plus))|a(?' . '>ck(?' . '>epsilon|prime|simeq)|r(?' . '>vee|wed))|c(?' . '>ong|y)|e(?' . '>mptyv' . '|t(?' . '>ween|a|h))|l(?' . '>ock|a(?' . '>cktriangle(?' . '>right|down' . '|left|)|nk)|k(?' . '>34|1(?' . '>2|4)))|n(?' . '>ot|e(?' . '>quiv|))|o(' . '?' . '>wtie|pf|x(?' . '>minus|plus|box|D(?' . '>L|R|l|r)|H(?' . '>D|U|d' . '|u|)|U(?' . '>L|R|l|r)|V(?' . '>H|L|R|h|l|r|)|d(?' . '>L|R|l|r)|h(?' . '>D|U|d|u)|u(?' . '>L|R|l|r)|v(?' . '>H|L|R|h|l|r|)))|s(?' . '>emi|cr|im' . '|ol(?' . '>hsub|b|))|u(?' . '>ll|mp(?' . '>E|)))|c(?' . '>ylcty|lubs|td' . 'ot|dot|fr|ir(?' . '>fnint|scir|mid|E|c(?' . '>eq|)|)|a(?' . '>cute|ret|' . 'p(?' . '>brcup|and|dot|c(?' . '>ap|up)|s|))|c(?' . '>edil|irc|ups(?' . '>sm|)|a(?' . '>ron|ps))|e(?' . '>mptyv|nt)|h(?' . '>eck|cy|i)|o(?' . '>' . 'ngdot|lon(?' . '>eq|)|m(?' . '>ma(?' . '>t|)|p(?' . '>lexes|fn|))|p(?' . '>f|y(?' . '>sr|)))|r(?' . '>arr|oss)|s(?' . '>cr|u(?' . '>b(?' . '>e|)|' . 'p(?' . '>e|)))|u(?' . '>larrp|darr(?' . '>l|r)|esc|p(?' . '>brcap|dot|o' . 'r|c(?' . '>ap|up)|s|)|r(?' . '>vearrowleft|arr(?' . '>m|)|ren|ly(?' . '>eqprec|wedge|vee)))|w(?' . '>conint|int))|d(?' . '>bkarow|dotseq|wangl' . 'e|lcrop|harl|tdot|Har|jcy|a(?' . '>gger|leth|shv|rr)|c(?' . '>aron|y)|e' . '(?' . '>mptyv|lta|g)|f(?' . '>isht|r)|i(?' . '>amond(?' . '>suit|)|sin|' . 'v(?' . '>ide|onx))|o(?' . '>ublebarwedge|wndownarrows|llar|pf|t(?' . '>' . 'eqdot|))|r(?' . '>bkarow|c(?' . '>orn|rop))|s(?' . '>trok|ol|c(?' . '>r' . '|y))|z(?' . '>igrarr|cy))|e(?' . '>rarr|dot|fr|a(?' . '>cute|ster)|c(?' . '>aron|ir(?' . '>c|)|y)|g(?' . '>rave|s(?' . '>dot|)|)|l(?' . '>inters|l' . '|s(?' . '>dot|)|)|m(?' . '>acr|pty|sp(?' . '>1(?' . '>3|4)|))|n(?' . '>' . 'sp|g)|o(?' . '>gon|pf)|p(?' . '>lus|ar(?' . '>sl|)|si)|q(?' . '>vparsl|' . 'colon|u(?' . '>ivDD|als|est))|s(?' . '>dot|cr|im)|t(?' . '>a|h)|u(?' . '>ml|ro)|x(?' . '>cl|p(?' . '>onentiale|ectation)))|f(?' . '>allingdotse' . 'q|partint|emale|ilig|jlig|nof|scr|cy|f(?' . '>ilig|l(?' . '>lig|ig)|r)|' . 'l(?' . '>lig|tns|at)|o(?' . '>pf|r(?' . '>all|kv))|r(?' . '>own|a(?' . '>sl|c(?' . '>45|78|1(?' . '>3|4|5|6|8)|2(?' . '>3|5)|3(?' . '>4|5|8)|5(' . '?' . '>6|8)))))|g(?' . '>vertneqq|breve|imel|rave|dot|jcy|opf|El|fr|a(?' . '>cute|mma(?' . '>d|)|p)|c(?' . '>irc|y)|e(?' . '>qq|s(?' . '>dot(?' . '>o(?' . '>l|)|)|cc|l(?' . '>es|)|)|)|g|l(?' . '>E|a|j|)|n(?' . '>sim|ap' . '|e(?' . '>qq|))|s(?' . '>cr|im(?' . '>e|l))|t(?' . '>quest|lPar|c(?' . '>ir|c)|r(?' . '>eqless|arr|dot)|))|h(?' . '>circ|Arr|fr|a(?' . '>irsp|l' . 'f|r(?' . '>dcy|r(?' . '>cir|w|)))|e(?' . '>arts|llip|rcon)|o(?' . '>mth' . 't|rbar|arr|pf)|s(?' . '>trok|cr)|y(?' . '>bull|phen))|i(?' . '>acute|gr' . 'ave|quest|tilde|jlig|prod|fr|c(?' . '>irc|y|)|e(?' . '>xcl|cy)|i(?' . '>iint|nfin|ota)|m(?' . '>ped|of|a(?' . '>gline|cr))|n(?' . '>care|odot|' . 'fin(?' . '>tie|)|t(?' . '>larhk|cal))|o(?' . '>gon|cy|pf|ta)|s(?' . '>c' . 'r|in(?' . '>dot|E|s(?' . '>v|)|v))|u(?' . '>kcy|ml))|j(?' . '>math|ukcy' . '|opf|fr|c(?' . '>irc|y)|s(?' . '>ercy|cr))|k(?' . '>green|appa|hcy|jcy|' . 'opf|scr|fr|c(?' . '>edil|y))|l(?' . '>vertneqq|Barr|Har|jcy|par(?' . '>' . 'lt|)|gE|ur(?' . '>dshar|uhar)|A(?' . '>tail|arr)|E|a(?' . '>emptyv|cute' . '|gran|mbda|quo|ng(?' . '>le|d)|rr(?' . '>bfs|sim|fs|hk|lp|pl|tl|)|p|t(?' . '>ail|e(?' . '>s|)|))|b(?' . '>arr|brk|r(?' . '>ac(?' . '>e|k)|k(?' . '>' . 'sl(?' . '>d|u)|e)))|c(?' . '>aron|e(?' . '>dil|il)|y)|d(?' . '>ca|sh|r(' . '?' . '>ushar|dhar))|e(?' . '>ft(?' . '>rightharpoons|harpoon(?' . '>dow' . 'n|up))|q|s(?' . '>dot(?' . '>o(?' . '>r|)|)|cc|g(?' . '>es|)|s(?' . '>d' . 'ot|gtr|eq(?' . '>qgtr|gtr))|))|f(?' . '>isht|r)|h(?' . '>arul|blk)|l(?' . '>corner|hard|arr|tri|)|m(?' . '>idot|oust)|n(?' . '>sim|ap|e(?' . '>qq|' . '))|o(?' . '>oparrowright|ngleftarrow|times|a(?' . '>ng|rr)|p(?' . '>lus' . '|ar|f)|w(?' . '>ast|bar)|z(?' . '>enge|f))|r(?' . '>hard|arr|tri|m)|s(?' . '>aquo|trok|cr|im(?' . '>e|g))|t(?' . '>quest|hree|imes|larr|c(?' . '>ir' . '|c)|r(?' . '>Par|i)|))|m(?' . '>DDot|dash|lcp|scr|fr|ho|a(?' . '>rker|c' . 'r|l(?' . '>tese|e)|p)|c(?' . '>omma|y)|i(?' . '>cro|nus(?' . '>d(?' . '>u|)|)|d(?' . '>cir|))|o(?' . '>dels|pf)|u(?' . '>map|))|n(?' . '>dash|' . 'jcy|fr|is(?' . '>d|)|G(?' . '>g|t)|L(?' . '>eftarrow|l|t(?' . '>v|))|V(' . '?' . '>Dash|dash)|a(?' . '>cute|bla|tur(?' . '>als|)|ng|p(?' . '>prox|i' . 'd|os|E))|b(?' . '>ump(?' . '>e|)|sp)|c(?' . '>edil|ong(?' . '>dot|)|up|' . 'a(?' . '>ron|p)|y)|e(?' . '>arhk|xist|Arr|dot|sim)|g(?' . '>sim|tr|e(?' . '>q|s))|h(?' . '>Arr|par)|l(?' . '>sim|tri(?' . '>e|)|dr|E|e(?' . '>ft(?' . '>rightarrow|arrow)|s))|o(?' . '>pf|t(?' . '>niv(?' . '>a|b|c)|in(?' . '>dot|E|v(?' . '>b|c)|)|))|p(?' . '>olint|ar(?' . '>allel|sl|t)|r)|r(?' . '>Arr|arr(?' . '>c|w|))|s(?' . '>hortmid|ime|cr|u(?' . '>b(?' . '>E|)|p(' . '?' . '>set(?' . '>eqq|)|)))|t(?' . '>riangleright|ilde|lg)|u(?' . '>m(?' . '>ero|sp|)|)|v(?' . '>infin|Dash|Harr|dash|sim|ap|g(?' . '>e|t)|l(?' . '>Arr|e|t(?' . '>rie|))|r(?' . '>trie|Arr))|w(?' . '>near|Arr|ar(?' . '>' . 'row|hk)))|o(?' . '>elig|hbar|vbar|opf|uml|ti(?' . '>mesas|lde)|S|a(?' . '>cute|st)|c(?' . '>ir(?' . '>c|)|y)|d(?' . '>blac|sold|ash|iv)|f(?' . '>cir|r)|g(?' . '>rave|on|t)|l(?' . '>arr|ine|c(?' . '>ross|ir)|t)|m(?' . '>acr|ega|i(?' . '>cron|nus|d))|p(?' . '>erp|ar)|r(?' . '>slope|igof|arr' . '|or|d(?' . '>erof|f|m|)|v|)|s(?' . '>lash|ol))|p(?' . '>uncsp|ar(?' . '>a|s(?' . '>im|l)|t)|cy|er(?' . '>tenk|cnt|iod|mil|p)|fr|h(?' . '>one|i' . ')|i(?' . '>tchfork|v|)|l(?' . '>anck(?' . '>h|)|us(?' . '>acir|cir|sim|' . 'two|mn|d(?' . '>o|u)|e|))|o(?' . '>intint|und|pf)|r(?' . '>urel|ime(?' . '>s|)|ec(?' . '>approx|sim|eq|n(?' . '>approx|eqq|sim)|)|E|o(?' . '>d|f(' . '?' . '>alar|line|surf)|p))|s(?' . '>cr|i))|q(?' . '>prime|opf|scr|fr|u(' . '?' . '>atint|est|ot))|r(?' . '>uluhar|moust|nmid|rarr|Har|lm|A(?' . '>t' . 'ail|arr)|a(?' . '>emptyv|quo|ng(?' . '>d|e)|rr(?' . '>bfs|sim|ap|fs|hk|' . 'pl|tl|c|w)|c(?' . '>ute|e)|t(?' . '>ail|io(?' . '>nals|)))|b(?' . '>brk' . '|rk(?' . '>sl(?' . '>d|u)|e))|c(?' . '>aron|edil|ub|y)|d(?' . '>ldhar|q' . 'uo|ca|sh)|e(?' . '>aline|ct|g)|f(?' . '>isht|r)|h(?' . '>ar(?' . '>d|u(' . '?' . '>l|))|o(?' . '>v|))|i(?' . '>singdotseq|ghtleft(?' . '>harpoons|a' . 'rrows)|ng)|o(?' . '>times|a(?' . '>ng|rr)|p(?' . '>lus|ar|f))|p(?' . '>' . 'polint|ar(?' . '>gt|))|s(?' . '>aquo|cr|h|q(?' . '>uo|b))|t(?' . '>hree' . '|imes|ri(?' . '>ltri|))|x)|s(?' . '>padesuit|acute|bquo|rarr|zlig|dot(?' . '>b|e|)|fr|c(?' . '>polint|aron|edil|irc|E|n(?' . '>sim|E)|y)|e(?' . '>a' . 'rhk|swar|Arr|ct|mi|xt)|h(?' . '>ortparallel|arp|c(?' . '>hcy|y)|y)|i(?' . '>gma(?' . '>v|)|m(?' . '>plus|rarr|dot|eq|ne|g(?' . '>E|)|l(?' . '>E|)|' . '))|m(?' . '>eparsl|ashp|ile|t(?' . '>e(?' . '>s|)|))|o(?' . '>ftcy|pf|l' . '(?' . '>b(?' . '>ar|)|))|q(?' . '>uarf|su(?' . '>pset|b)|c(?' . '>ap(?' . '>s|)|up(?' . '>s|)))|s(?' . '>etmn|cr)|t(?' . '>raight(?' . '>epsilon|p' . 'hi)|ar(?' . '>f|))|u(?' . '>cc(?' . '>curlyeq|napprox|approx|)|ng|b(?' . '>edot|mult|plus|rarr|dot|E|s(?' . '>etneq(?' . '>q|)|im|u(?' . '>b|p))|' . ')|m|p(?' . '>larr|mult|plus|hs(?' . '>ol|ub)|nE|1|2|3|d(?' . '>sub|ot)|' . 'e(?' . '>dot|)|s(?' . '>et(?' . '>eqq|neq)|im|u(?' . '>b|p))|))|w(?' . '>nwar|Arr|ar(?' . '>hk|r)))|t(?' . '>woheadrightarrow|elrec|prime|fr|a(' . '?' . '>rget|u)|c(?' . '>aron|edil|y)|h(?' . '>orn|e(?' . '>re4|ta(?' . '>sym|)))|i(?' . '>mes(?' . '>b(?' . '>ar|)|d|)|nt)|o(?' . '>ea|p(?' . '>bot|cir|f(?' . '>ork|)))|r(?' . '>pezium|ade|i(?' . '>angle(?' . '>dow' . 'n|q|)|minus|plus|time|dot|sb))|s(?' . '>trok|hcy|c(?' . '>r|y)))|u(?' . '>wangle|grave|macr|Har|scr|uml|br(?' . '>eve|cy)|a(?' . '>cute|rr)|c(?' . '>irc|y)|d(?' . '>blac|arr|har)|f(?' . '>isht|r)|h(?' . '>arl|blk)|l(?' . '>tri|c(?' . '>orner|rop))|o(?' . '>gon|pf)|p(?' . '>uparrows|si(?' . '>' . 'h|))|r(?' . '>ing|tri|c(?' . '>orner|rop))|t(?' . '>ilde|dot))|v(?' . '>zigzag|dash|nsub|rtri|Bar(?' . '>v|)|opf|cy|fr|a(?' . '>ngrt|r(?' . '>' . 'triangleleft|supsetneqq|kappa))|e(?' . '>llip|rt|e(?' . '>bar|eq))|s(?' . '>cr|u(?' . '>pne|bn(?' . '>E|e))))|w(?' . '>circ|opf|scr|ed(?' . '>bar|' . 'geq)|fr|p|r)|x(?' . '>wedge|hArr|lArr|map|nis|scr|vee|fr|i|o(?' . '>dot' . '|pf))|y(?' . '>icy|opf|scr|ac(?' . '>ute|y)|en|fr|c(?' . '>irc|y)|u(?' . '>cy|ml))|z(?' . '>igrarr|acute|dot|eta|hcy|opf|scr|fr|c(?' . '>aron|y)|' . 'w(?' . '>nj|j))|#(?' . '>\d+|x[0-9a-fA-F]+));'

ENT_NBSP

Regular expression to match all forms of the non-breaking space entity.

public mixed ENT_NBSP = '&(?' . '>nbsp|#(?' . '>x0*A0|0*160));'

TAB_SUBSTITUTE

public string TAB_SUBSTITUTE = "​    ​"

Used to force the browser not to collapse tabs.

This will normally be replaced in the final output with a real tab character wrapped in a span with "white-space: pre" applied to it. But if this substitute string somehow makes it into the final output, it will still look like an appropriately sized string of white space.

Properties

$context

public static array<string|int, mixed> $context = [ // Assume UTF-8 until proven otherwise. 'utf8' => true, 'character_set' => 'UTF-8', // Define a list of icons used across multiple places. 'stable_icons' => ['xx', 'thumbup', 'thumbdown', 'exclamation', 'question', 'lamp', 'smiley', 'angry', 'cheesy', 'grin', 'sad', 'wink', 'poll', 'moved', 'recycled', 'clip'], // Define an array for custom profile fields placements. 'cust_profile_fields_placement' => ['standard', 'icons', 'above_signature', 'below_signature', 'below_avatar', 'above_member', 'bottom_poster', 'before_member', 'after_member'], // Define an array for content-related <meta> elements (e.g. description, // keywords, Open Graph) for the HTML head. 'meta_tags' => [], // Define an array of allowed HTML tags. 'allowed_html_tags' => ['<img>', '<div>'], // Define a list of allowed tags for descriptions. 'description_allowed_tags' => ['abbr', 'anchor', 'b', 'br', 'center', 'color', 'font', 'hr', 'i', 'img', 'iurl', 'left', 'li', 'list', 'ltr', 'pre', 'right', 's', 'sub', 'sup', 'table', 'td', 'tr', 'u', 'url'], // Define a list of deprecated BBC tags. // Even when enabled, they'll only work in old posts and not new ones. 'legacy_bbc' => ['acronym', 'bdo', 'black', 'blue', 'flash', 'ftp', 'glow', 'green', 'move', 'red', 'shadow', 'white'], // Define a list of BBC tags that require permissions to use. 'restricted_bbc' => ['html'], // Login Cookie times. Format: time => txt 'login_cookie_times' => [3153600 => 'always_logged_in', 60 => 'one_hour', 1440 => 'one_day', 10080 => 'one_week', 43200 => 'one_month'], 'show_spellchecking' => false, ]

SMF's venerable $context variable, now available as Utils::$context.

$smcFunc

public static array<string|int, mixed> $smcFunc = ['entity_decode' => __CLASS__ . '::entityDecode', 'sanitize_entities' => __CLASS__ . '::sanitizeEntities', 'entity_fix' => __CLASS__ . '::entityFix', 'htmlspecialchars' => __CLASS__ . '::htmlspecialchars', 'htmltrim' => __CLASS__ . '::htmlTrim', 'strlen' => __CLASS__ . '::entityStrlen', 'strpos' => __CLASS__ . '::entityStrpos', 'substr' => __CLASS__ . '::entitySubstr', 'strtolower' => __CLASS__ . '::strtolower', 'strtoupper' => __CLASS__ . '::strtoupper', 'ucfirst' => __CLASS__ . '::ucfirst', 'ucwords' => __CLASS__ . '::ucwords', 'convert_case' => __CLASS__ . '::convertCase', 'normalize' => __CLASS__ . '::normalize', 'truncate' => __CLASS__ . '::truncate', 'json_encode' => __CLASS__ . '::jsonEncode', 'json_decode' => 'smf_json_decode', 'random_int' => __CLASS__ . '::randomInt', 'random_bytes' => __CLASS__ . '::randomBytes']

Backward compatibility aliases of various utility functions.

$backcompat

private static array<string|int, mixed> $backcompat = ['prop_names' => ['context' => 'context', 'smcFunc' => 'smcFunc']]

BackwardCompatibility settings for this class.

Methods

adjustHeadingLevels()

Adjusts the heading levels of h1-h6 elements in a string in order to fit the needs of a particular location in the output HTML.

public static adjustHeadingLevels(mixed $str[, int|null $modifier = 0 ]) : mixed

For example, setting $modifier to 1 will change h1 into h2, h5 into h6, etc.

If the adjusted tag for the heading would be invalid (e.g. h7 or h0), then the tag will be changed to a simple div.

Any attributes of the adjusted elements will be preserved unchanged. For example, <h1 class="bbc_h1"> might become <h5 class="bbc_h1">.

As a general rule, this method should be called from theme templates rather than source files, since only the template really knows what level of adjustment is necessary.

Parameters
$str : mixed

The string in which to adjust heading levels. If a non-string value is given, it will be returned unchanged.

$modifier : int|null = 0

The amount by which to adjust heading levels. If null, all headings will be converted to div elements. Default: 0.

Return values
mixed

The adjusted version of $str.

arrayLength()

Gets the total byte length of all leaf nodes in an array.

public static arrayLength(array<string|int, mixed> $array) : int
Parameters
$array : array<string|int, mixed>

The array.

Return values
int

Total byte length of all leaf nodes in an array.

buildRegex()

Creates optimized regular expressions from arrays of strings.

public static buildRegex(array<string|int, mixed> $strings[, string $delim = null ][, bool $return_array = false ]) : string|array<string|int, mixed>

An optimized regex built using this function will be much faster than a simple regex built using implode('|', $strings) --- anywhere from several times to several orders of magnitude faster.

However, the time required to build and execute the optimized regex is approximately equal to the time it takes to execute the simple regex. Therefore, it is usually only worth calling this method if the resulting regex will be used more than once.

Because PHP places an upper limit on the allowed length of a regex, very large arrays of $strings may not fit in a single regex. Normally, the excess strings will simply be dropped. However, if the $return_array parameter is set to true, this function will build as many regexes as necessary to accommodate everything in $strings and return them in an array. You will need to iterate through all elements of the returned array in order to test all possible matches.

Parameters
$strings : array<string|int, mixed>

An array of strings to make a regex for.

$delim : string = null

Optional delimiter character to pass to preg_quote().

$return_array : bool = false

If true, returns an array of regexes.

Return values
string|array<string|int, mixed>

One or more regular expressions to match any of the input strings.

casefold()

Convenience alias of Utils::convertCase($string, 'fold')

public static casefold(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The casefolded version of the input string.

checkMimeType()

Checks whether a file or data has the expected MIME type.

public static checkMimeType(string $data, string $type_pattern[, bool $is_path = false ]) : int
Parameters
$data : string

The data to check, or the path or URL of a file to check.

$type_pattern : string

A regex pattern to match the acceptable MIME types.

$is_path : bool = false

If true, $data is a path or URL to a file.

Return values
int

1 if the detected MIME type matches the pattern, 0 if it doesn't, or 2 if we can't check.

cleanXml()

Clean up the XML to make sure it doesn't contain invalid characters.

public static cleanXml(string $string) : string

See https://www.w3.org/TR/xml/#charsets

Parameters
$string : string

The string to clean

Return values
string

The cleaned string

convertCase()

Performs case conversion on UTF-8 strings.

public static convertCase(string $string, string $case[, bool $simple = false ][, string $form = 'c' ][, bool $mb4 = false ]) : string

Similar to, but with more capabilities than, mb_convert_case().

Note that setting $form to 'kc_casefold' will override any value of $case and will always fold the case of the string. Also note that setting $form to 'kc_casefold' is not the same as setting $case to 'fold' and $form to 'kc'; specifically, setting $case to 'fold' and $form to 'kc' does not remove "default ignorable code points" from the string, whereas setting $form to 'kc_casefold' does. See notes on the normalize() method for more information about when 'kc_casefold' should be used.

Parameters
$string : string

The input string.

$case : string

One of 'upper', 'lower', 'fold', 'title', 'ucfirst', or 'ucwords'.

$simple : bool = false

If true, use simple maps instead of full maps. Default: false.

$form : string = 'c'

A Unicode normalization form: 'c', 'd', 'kc', 'kd', or 'kc_casefold'.

$mb4 : bool = false

If true, always decode 4-byte UTF-8 characters. Default: false.

Return values
string

The normalized string.

emitFile()

Emits a file for download. Mostly used for attachments.

public static emitFile(array<string|int, mixed>|ArrayAccess $file[, bool $show_thumb = false ]) : void
Parameters
$file : array<string|int, mixed>|ArrayAccess

Information about the file. Must be either an array or an object that implements the \ArrayAccess interface.

$show_thumb : bool = false

Whether to send the image's embedded thumbnail, if it has one.

entityDecode()

Decodes and sanitizes HTML entities.

public static entityDecode(string $string[, bool $mb4 = false ][, int $flags = ENT_QUOTES | ENT_HTML5 ][, bool $nbsp_to_space = false ]) : string

If database does not support 4-byte UTF-8 characters, entities for 4-byte characters are left in place, unless the $mb4 argument is set to true.

Parameters
$string : string

The string in which to decode entities.

$mb4 : bool = false

If true, always decode 4-byte UTF-8 characters. Default: false.

$flags : int = ENT_QUOTES | ENT_HTML5

Flags to pass to html_entity_decode. Default: ENT_QUOTES | ENT_HTML5.

$nbsp_to_space : bool = false

If true, decode ' ' to space character. Default: false.

Return values
string

The string with the entities decoded.

entityFix()

Fixes double-encoded entities in a string.

public static entityFix(string $string) : string
Parameters
$string : string

The string.

Return values
string

The fixed string.

entityStrlen()

Like standard mb_strlen(), except that it counts HTML entities as single characters. This essentially amounts to getting the length of the string as it would appear to a human reader.

public static entityStrlen(string $string) : int
Parameters
$string : string

The string.

Return values
int

The length of the string.

entityStrpos()

Like standard mb_strpos(), except that it counts HTML entities as single characters.

public static entityStrpos(string $haystack, string $needle[, int $offset = 0 ]) : int|false
Parameters
$haystack : string

The string to search in.

$needle : string

The substring to search for.

$offset : int = 0

Search offset within $haystack.

Return values
int|false

Position of $needle in $haystack, or false on failure.

entityStrSplit()

Like standard mb_str_split(), except that it counts HTML entities as single characters.

public static entityStrSplit(string $string[, int $length = 1 ]) : array<string|int, mixed>
Parameters
$string : string

The input string.

$length : int = 1

Maximum character length of the substrings to return.

Return values
array<string|int, mixed>

The extracted substrings.

entitySubstr()

Like standard mb_substr(), except that it counts HTML entities as single characters.

public static entitySubstr(string $string, int $offset[, int $length = null ]) : string
Parameters
$string : string

The input string.

$offset : int

Offset where substring will start.

$length : int = null

Maximum length, in characters, of the substring.

Return values
string

The substring.

escapeJavaScript()

Escapes (replaces) characters in strings to make them safe for use in JavaScript

public static escapeJavaScript(string $string[, bool $as_json = false ]) : string
Parameters
$string : string

The string to escape

$as_json : bool = false

If true, escape as double-quoted string. Default false.

Return values
string

The escaped string

escapestringRecursive()

Recursively applies database string escaping to all elements of an array.

public static escapestringRecursive(array<string|int, mixed>|string $var) : array<string|int, mixed>|string

Affects both keys and values of arrays.

Parameters
$var : array<string|int, mixed>|string

A string or array of strings to escape

Return values
array<string|int, mixed>|string

The escaped string or array of escaped strings

exportStatic()

Provides a way to export a class's public static properties and methods to global namespace.

public static exportStatic() : void

To do so:

  1. Use this trait in the class.
  2. At the END of the class's file, call its exportStatic() method.

Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.

Regarding the $backcompat items:

A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names'].

$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.

Adding non-static properties to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.

extractWords()

Extracts all the words in a string.

public static extractWords(string $string[, int $level = 0 ]) : array<string|int, mixed>

Emoji characters count as words and are retained in the result. Whitespace, punctuation, and other symbols are discarded.

E.g.: 'A red fox! 🦊' --> ['A', 'red', 'fox', '🦊']

Parameters
$string : string

The string to extract words from.

$level : int = 0

See documentation for self:sanitizeChars(). Default: 0.

Return values
array<string|int, mixed>

An array of strings.

fixUtf8mb4()

Converts four-byte Unicode characters to entities, but only if the database can't handle four-byte characters natively.

public final static fixUtf8mb4(string $string) : string
Parameters
$string : string

A UTF-8 string.

Return values
string

The string, with four-byte chars encoded as entities.

getCallable()

Parses the given input to determine if it represents a callable entity.

public static getCallable(string|callable $input[, bool|null $ignore_errors = null ]) : callable|false

This method supports various formats of callables, including closures, callable arrays, static methods, and class methods with optional instance creation.

  • If a class method is specified with a "#", it attempts to create a new instance of the class.
  • If a static method is specified, it validates the method is callable.
  • If input is a closure or callable array, it checks its validity.
  • Plain functions are validated as callable.
  • Objects themselves are not accepted as callables.
Parameters
$input : string|callable

Input to parse as a callable.

$ignore_errors : bool|null = null

Optional. Whether to suppress errors if the callable is invalid. Defaults to the value of Utils::$context['ignore_hook_errors'].

Return values
callable|false

Returns the callable if valid, or false on failure.

getMimeType()

Attempts to determine the MIME type of some data or a file.

public static getMimeType(string $data[, string $is_path = false ]) : string|false
Parameters
$data : string

The data to check, or the path or URL of a file to check.

$is_path : string = false

If true, $data is a path or URL to a file.

Return values
string|false

A MIME type, or false if we cannot determine it.

htmlspecialchars()

Wrapper for standard htmlspecialchars() that ensures the output respects the database's support (or lack thereof) for four-byte UTF-8 characters.

public static htmlspecialchars(string $string[, int $flags = ENT_COMPAT ][, string $encoding = 'UTF-8' ]) : string
Parameters
$string : string

The string being converted.

$flags : int = ENT_COMPAT

Bitmask of flags to pass to standard htmlspecialchars(). Default is ENT_COMPAT.

$encoding : string = 'UTF-8'

Character encoding. Default is UTF-8.

Return values
string

The converted string.

htmlspecialcharsDecode()

Replaces special entities in strings with the real characters.

public static htmlspecialcharsDecode(string $string[, int $flags = ENT_QUOTES ][, string $encoding = 'UTF-8' ]) : string|false

Functionally equivalent to htmlspecialchars_decode(), except that this also replaces ' ' with a simple space character.

Parameters
$string : string

A string.

$flags : int = ENT_QUOTES

Bitmask of flags to pass to standard htmlspecialchars(). Default is ENT_QUOTES.

$encoding : string = 'UTF-8'

Character encoding. Default is UTF-8.

Return values
string|false

The string without entities, or false on failure.

htmlspecialcharsRecursive()

Recursively applies self::htmlspecialchars() to all elements of an array.

public static htmlspecialcharsRecursive(mixed $var[, int $flags = ENT_COMPAT ][, string $encoding = 'UTF-8' ]) : array<string|int, mixed>|string

Only affects values.

Parameters
$var : mixed

The string or array of strings to add entities to

$flags : int = ENT_COMPAT

Bitmask of flags to pass to standard htmlspecialchars(). Default is ENT_COMPAT.

$encoding : string = 'UTF-8'

Character encoding. Default is UTF-8.

Return values
array<string|int, mixed>|string

The string or array of strings with entities added

htmlTrim()

Like standard trim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.

public static htmlTrim(string $string) : string|false
Parameters
$string : string

The string.

Return values
string|false

The trimmed string, or false on failure.

htmlTrimLeft()

Like standard ltrim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.

public static htmlTrimLeft(string $string) : string|false
Parameters
$string : string

The string.

Return values
string|false

The trimmed string, or false on failure.

htmlTrimRecursive()

Recursively applies self::htmlTrim to all elements of an array.

public static htmlTrimRecursive(array<string|int, mixed>|string $var) : array<string|int, mixed>|string|false

Only affects values.

Parameters
$var : array<string|int, mixed>|string

The string or array of strings to trim.

Return values
array<string|int, mixed>|string|false

The trimmed string or array of trimmed strings.

htmlTrimRight()

Like standard rtrim(), except that it also trims &nbsp; entities, control characters, and Unicode whitespace characters beyond the ASCII range.

public static htmlTrimRight(string $string) : string|false
Parameters
$string : string

The string.

Return values
string|false

The trimmed string, or false on failure.

jsonDecode()

Wrapper function for json_decode() with error handling.

public static jsonDecode(string $json[, bool|null $associative = null ][, int $depth = 512 ][, int $flags = 0 ][, bool $should_log = true ]) : mixed
Parameters
$json : string

The string to decode.

$associative : bool|null = null

Whether to force JSON objects to be returned as associative arrays. SMF nearly always wants this to be true, but for the sake of consistency with json_decode(), the default is null.

$depth : int = 512

Maximum nesting depth of the structure being decoded. The value must be greater than 0, and less than or equal to 2147483647.

$flags : int = 0

Bitmask of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR

$should_log : bool = true

Whether to log errors. Default: true.

Return values
mixed

The decoded data.

jsonEncode()

Wrapper function for json_encode().

public static jsonEncode(mixed $value[, int $flags = 0 ][, int $depth = 512 ]) : string|false

This method exists merely to complement Utils::jsonDecode() for the sake of completeness. Calling this method is functionally identical to calling json_encode() directly.

Parameters
$value : mixed

The value to encode.

$flags : int = 0

Bitmask of flags for json_encode(). Default: 0.

$depth : int = 512

Maximum depth. Default: 512.

Return values
string|false

The decoded data.

load()

(Re)initializes some $context values that need to be set dynamically.

public static load() : void

makeWritable()

Tries different modes to make files or directories writable.

public static makeWritable(string $path[, array<string|int, mixed>|string|null $chmod = null ]) : bool

Wrapper function for PHP's chmod().

Parameters
$path : string

The full path of the file or directory.

$chmod : array<string|int, mixed>|string|null = null

Specify a chmod, if left blank, SMF will auto pick the writable values.

Return values
bool

Whether the file/dir exists and is now writable.

normalize()

Performs Unicode normalization on a UTF-8 string.

public static normalize(string $string[, string $form = 'c' ]) : string

Note that setting $form to 'kc_casefold' will cause the string's case to be folded and will also remove all "default ignorable code points" from the string. It should be used (1) when validating identifier strings that must be unambiguously unique, such as domain names, file names, or even SMF user names, or (2) when performing caseless matching of strings, such as when performing a search or checking for censored words in a post.

Parameters
$string : string

The input string.

$form : string = 'c'

A Unicode normalization form: 'c', 'd', 'kc', 'kd', or 'kc_casefold'.

Return values
string

The normalized string.

normalizeSpaces()

Normalizes space characters and line breaks.

public static normalizeSpaces(string $string[, bool $vspace = true ][, bool $hspace = false ][, array<string|int, mixed> $options = [] ]) : string|false
Parameters
$string : string

The string to sanitize.

$vspace : bool = true

If true, replaces all line breaks and vertical space characters with "\n". Default: true.

$hspace : bool = false

If true, replaces horizontal space characters with a plain " " character. (Note: tabs are not replaced unless the 'replace_tabs' option is supplied.) Default: false.

$options : array<string|int, mixed> = []

An array of boolean options. Possible values are:

  • no_breaks: Vertical spaces are replaced by " " instead of "\n".
  • replace_tabs: If true, tabs are replaced by " " chars.
  • collapse_hspace: If true, removes extra horizontal spaces.
Return values
string|false

The sanitized string, or false on failure.

obExit()

Ends execution. Takes care of template loading and remembering the previous URL.

public static obExit([bool $header = null ][, bool $do_footer = null ][, bool $from_index = false ][, bool $from_fatal_error = false ]) : void
Parameters
$header : bool = null

Whether to do the header

$do_footer : bool = null

Whether to do the footer

$from_index : bool = false

Whether we're coming from the board index

$from_fatal_error : bool = false

Whether we're coming from a fatal error

randomBytes()

Wrapper for random_bytes() that sets a default length.

public static randomBytes([int $length = 64 ]) : string

Only exists for backward compatibility purposes.

Parameters
$length : int = 64

Number of bytes to return. Default: 64.

Return values
string

A string of random bytes.

randomInt()

Wrapper for random_int() that sets default values.

public static randomInt([int $min = 0 ][, int $max = PHP_INT_MAX ]) : int

Only exists for backward compatibility purposes.

Parameters
$min : int = 0

Minimum value. Default: 0.

$max : int = PHP_INT_MAX

Maximum value. Default: PHP_INT_MAX.

Return values
int

A random integer.

redirectexit()

Make sure the browser doesn't come back and repost the form data.

public static redirectexit([string $setLocation = '' ][, bool $refresh = false ][, bool $permanent = false ]) : void

Should be used whenever anything is posted.

Parameters
$setLocation : string = ''

The URL to redirect them to

$refresh : bool = false

Whether to use a meta refresh instead

$permanent : bool = false

Whether to send a 301 Moved Permanently instead of a 302 Moved Temporarily

safeSerialize()

Safe serialize() replacement.

public static safeSerialize(mixed $value) : string
  • Recursive.
  • Outputs a strict subset of PHP's native serialized representation.
  • Does not serialize objects.
Parameters
$value : mixed
Return values
string

safeUnserialize()

Safe unserialize() replacement

public static safeUnserialize(string $str) : mixed
  • Accepts a strict subset of PHP's native serialized representation.
  • Does not unserialize objects.
Parameters
$str : string

sanitizeChars()

Replaces invalid characters with a substitute.

public static sanitizeChars(string $string[, int $level = 0 ][, string|null $substitute = null ]) : string|false

!!! Warning !!! Setting $substitute to '' in order to delete invalid characters from the string can create unexpected security problems. See https://www.unicode.org/reports/tr36/#Deletion_of_Noncharacters for an explanation.

Parameters
$string : string

The string to sanitize.

$level : int = 0

Controls filtering of invisible formatting characters. 0: Allow valid formatting characters. Use for sanitizing text in posts. 1: Allow necessary formatting characters. Use for sanitizing usernames. 2: Disallow all formatting characters. Use for internal comparisons only, such as in the word censor, search contexts, etc. Default: 0.

$substitute : string|null = null

Replacement string for the invalid characters. If not set, the Unicode replacement character (U+FFFD) will be used (or a fallback like "?" if necessary).

Return values
string|false

The sanitized string, or false on failure.

sanitizeEntities()

Replaces HTML entities for invalid characters with a substitute.

public static sanitizeEntities(string $string[, string $substitute = '&#65533;' ]) : string

The default substitute is the entity for the replacement character U+FFFD (a.k.a. the question-mark-in-a-box).

!!! Warning !!! Setting $substitute to '' in order to delete invalid entities from the string can create unexpected security problems. See https://www.unicode.org/reports/tr36/#Deletion_of_Noncharacters for an explanation.

Parameters
$string : string

The string to sanitize.

$substitute : string = '&#65533;'

Replacement for the invalid entities. Default: '�'

Return values
string

The sanitized string.

semanticSplit()

Splits a string into its words, symbols, punctuation, and whitespace.

public static semanticSplit(string $string) : array<string|int, mixed>

E.g.: 'A red fox! 🦊' --> ['A', ' ', 'red', ' ', 'fox', '!', ' ', '🦊']

Parameters
$string : string

The string to split into semantic components.

Return values
array<string|int, mixed>

An array of strings.

sendHttpStatus()

Sends an appropriate HTTP status header based on a given status code.

public static sendHttpStatus(int $code[, string $status = '' ]) : void
Parameters
$code : int

The status code.

$status : string = ''

The status message. Set automatically if empty.

serverResponse()

Outputs a response.

public static serverResponse([string $data = '' ][, string $type = 'Content-Type: application/json' ]) : bool|void

It assumes the data is already a string.

Parameters
$data : string = ''

The data to print

$type : string = 'Content-Type: application/json'

The content type. Defaults to JSON.

Return values
bool|void

If $data is empty, false is returned, otherwise the response is sent and execution stopped.

shorten()

Like Utils::entitySubstr(), except that this also appends an ellipsis to the returned string to indicate that it was truncated (unless it wasn't truncated because it was already short enough).

public static shorten(string $subject, int $len) : string
Parameters
$subject : string

The string.

$len : int

How many characters to limit it to.

Return values
string

The shortened string.

stripslashesRecursive()

Recursively applies stripslashes() to all elements of an array.

public static stripslashesRecursive(array<string|int, mixed>|string $var[, int $level = 0 ]) : array<string|int, mixed>|string

Affects both keys and values of arrays.

Parameters
$var : array<string|int, mixed>|string

The string or array of strings to strip slashes from

$level : int = 0

= 0 What level we're at within the array (if called recursively)

Return values
array<string|int, mixed>|string

The string or array of strings with slashes stripped

strtolower()

Convenience alias of Utils::convertCase($string, 'lower')

public static strtolower(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The lowercase version of the input string.

strtotitle()

Convenience alias of Utils::convertCase($string, 'title')

public static strtotitle(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The titlecase version of the input string.

strtoupper()

Convenience alias of Utils::convertCase($string, 'upper')

public static strtoupper(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The uppercase version of the input string.

truncate()

Truncates a string to fit within the specified byte length, while making sure not to cut in the middle of an HTML entity or multi-byte character.

public static truncate(string $string, int $length) : string|false

The difference between this and the entitySubstr method is that this truncates the string to fit into a certain byte length, whereas entitySubstr truncates to fit into a certain visual character length. This difference is important when dealing with Unicode.

Parameters
$string : string

The input string.

$length : int

The maximum length, in bytes, of the returned string.

Return values
string|false

The truncated string, or false on error.

truncateArray()

Truncates the leaf nodes of an array so that their cumulative byte length fits within a specified maximum.

public static truncateArray(array<string|int, mixed> $array[, int $max_length = 1900 ]) : array<string|int, mixed>

The array's keys are not considered when calculating the total length.

Parameters
$array : array<string|int, mixed>

The array to truncate.

$max_length : int = 1900

The upperbound on the length.

Return values
array<string|int, mixed>

The truncated array.

ucfirst()

Convenience alias of Utils::convertCase($string, 'ucfirst')

public static ucfirst(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The string, but with the first character in titlecase.

ucwords()

Convenience alias of Utils::convertCase($string, 'ucwords')

public static ucwords(string $string) : string
Parameters
$string : string

The input string.

Return values
string

The string, but with the first character of each word in titlecase.

unescapestringRecursive()

Recursively removes database string escaping in all elements of an array.

public static unescapestringRecursive(array<string|int, mixed>|string $var) : array<string|int, mixed>|string

Affects both keys and values of arrays.

Parameters
$var : array<string|int, mixed>|string

The string or array of strings to unescape

Return values
array<string|int, mixed>|string

The unescaped string or array of unescaped strings

urldecodeRecursive()

Recursively applies urldecode() to all elements of an array.

public static urldecodeRecursive(array<string|int, mixed>|string $var[, int $level = 0 ]) : array<string|int, mixed>|string

Affects both keys and values of arrays.

Parameters
$var : array<string|int, mixed>|string

The string or array of strings to decode

$level : int = 0

Which level we're at within the array (if called recursively)

Return values
array<string|int, mixed>|string

The decoded string or array of decoded strings

loadFile()

Helper method for Utils::call_helper.

protected final static loadFile(string $string) : string|false

Receives a string and tries to figure it out if it contains info to load a file.

Checks for a '|' symbol and tries to load a file with the info given.

The string should be formatted as follows: 'path/to/file.php|whatever'.

You can use the following wildcards in the path:

  • $boarddir
  • $sourcedir
  • $themedir (only works if SMF\Theme has already been initialized)
Parameters
$string : string

The string containing a valid format.

Return values
string|false

The given string with the pipe and file info removed or false if the file couldn't be loaded.


        
On this page

Search results