This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".  
Status: 2024-10-07

Strings


cutOff

cuts off a string at given limit, appends a custom string if string to cut off is longer than limit, can purify broken markup string before return.

Strings::cutOff(string $sString = '', int $iLimit = 0, string $sAppendix = ' […]', bool $bPurify = true) : string

Example: cutOff at char 50, No Appendix, with bPurify: true (repair broken html string)

$sString = Strings::cutOff(
    '<p><strong>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</strong></p>',
    50,
    sAppendix: '',
    bPurify: true
);

Result of $sString

// type: string
'<p><strong>Lorem ipsum dolor sit <i>amet</i>, cons</strong></p>'

highlight_html

returns $sTag-encapsulated, highlighted html markup.

Strings::highlight_html(string $sMarkup = '', string $sTag = 'code', bool $bPurify = false) : string

Example: with bPurify: true (repair broken html string)

$sString = Strings::highlight_html(
            '<p><strong>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</strong>',
            bPurify: true
        );

Result of $sString

// type: string
'<code>&lt;<span style="color:#d02">p</span>&gt;&lt;<span style="color:#d02">strong</span>&gt;Lorem&nbsp;ipsum&nbsp;dolor&nbsp;sit&nbsp;&lt;
    <span style="color:#d02">i</span>&gt;amet&lt;/<span style="color:#d02">i</span>&gt;,&nbsp;consectetur&nbsp;adipiscing&nbsp;elit.&lt;/
    <span style="color:#d02">strong</span>&gt;&lt;/<span style="color:#d02">p</span>&gt;</code>'

isJson

checks whether a string is json.

Strings::isJson(string $sString = '') : bool

Example

// true
$bIsJson = Strings::isJson(
    '{"foo":"bar"}'
);

isMarkup

checks whether a string contains markup.

Strings::isMarkup(string $sString = '', bool $bPurify = true) : bool

Example

// true
$bIsMarkup = Strings::isMarkup(
    '<p><strong>Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit.</strong>',
);

isUtf8

checks whether a string is utf8.

Strings::isUtf8(string $sString = '') : bool

removeDoubleDotSlashesFromString

Strings::removeDoubleDotSlashesFromString(string $sString = '') : string

replaceMultipleForwardSlashesByOneFromString

Strings::replaceMultipleForwardSlashesByOneFromString(string $sString = '', bool $bIgnoreProtocols = false) : string

seofy

replaces special chars, umlauts by - (or given char).

Strings::seofy(string $sString = '', string $sReplacement = '-', bool $bStrToLower = true) : string

Example

$sSeofied = Strings::seofy('Straßenfest in München !');

Result

strassenfest-in-muenchen

tidy

cleans up a string by removing newlines, multiple whitespaces.

Strings::tidy(string $sString = '')

Example

$sTidy = Strings::tidy("<p><strong>
Lorem ipsum dolor sit <i>amet</i>,          
            consectetur adipiscing elit.

</strong></p>");

Result

<p><strong> Lorem ipsum dolor sit <i>amet</i>, consectetur adipiscing elit. </strong></p>

ulli

creates a markup html <ul>/<li> list on given data (string|array).

Strings::ulli(mixed $aData, array $aConfig = array('ul' => 'list-group', 'li' => 'text-break list-group-item bg-transparent', 'spanPrimary' => 'text-primary', 'spanInfo' => 'text-info', 'allocator' => '=>', 'arrayIdentifier' => 'array(...')) : string

Example

$sUlli = Strings::ulli(
    Config::MODULE()['DATATYPE']['class']['DTRoutingAdditional']
);

Result of $sUlli

<ul class="list-group">
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">name</span> <span class="text-info">=></span> DTRoutingAdditional</li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">file</span> <span class="text-info">=></span> DTRoutingAdditional.php</li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">extends</span> <span class="text-info">=></span> \\MVC\\DataType\\DTRoutingAdditional</li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">namespace</span> <span class="text-info">=></span> Foo\\DataType</li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">createHelperMethods</span> <span class="text-info">=></span> 1</li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">constant</span> <span class="text-info">=></span> </li>
    <li class="text-break list-group-item bg-transparent"><span class="text-primary">property</span> <span class="text-info">=></span> </li>
</ul>

uuid4

returns a random uuid Version4 string (8-4-4-4-12).

Strings::uuid4() : string

Example

$sUuid = Strings::uuid4();

Result

889abaf2-461d-42a1-86f4-07eb3e9876a5

createPassword

creates a password up to 57 chars.
Makes sure that at least 4 characters contain one of each lower, upper, int, special char.

Strings::createPassword(int $iMaxLength = 15, string $sCharSpecial = '#*!$.') : string

Example

$sPassword = Strings::createPassword();

Result

$cZY/iZncdgWwC8