PHP Advanced String Classes

PHP Advanced String Classes

Extended PHP strings processing library

Language Tools

WiseLoop PHP Advanced String Classes is the complete multi-byte and binary safe PHP string processing solution that enables you to: validate input data types (alpha, numeric, date, IP, email, URL, hex), change case, apply string effects (shorten, shuffle, scramble, reverse, make URL SEO friendly), generate passwords, generate GUIDs, process and extract characters, words and sentences, compute statistics (word count, unique word count, char count), numbers extraction, substring searching and replacing, padding, trimming, splitting, word wrapping, html processing, encrypting, encoding, censoring, spell checking, spell auto correcting etc.
All the methods and classes have full support for any language character set or alphabet through a customizable configuration class.

01. THESAURUS

Default Spell Checking

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apl');
echo 
$s->getClosestMatch();
echo 
'<pre>' print_r($s->getMatches(), true) . '</pre>';
echo 
'<pre>' print_r($s->getMatches(20), true) . '</pre>';
echo 
'<br/>';
$s->set('The qiuck fox jmepud oevr the lazy dog.');
echo 
$s->spellEmphasize() . '<br/>';
echo 
$s->spellAutoCorrect();
echo 
'<pre>' print_r($s->spellCheck(), true) . '</pre>';

Result:

applique
Array
(
)
Array
(
    [0] => Array
        (
            [word] => applique
            [percent] => 49.06
        )

    [1] => Array
        (
            [word] => applemubojumbo
            [percent] => 27.57
        )

)

the qiuck fox jmepud oevr the lazy dog.
The quick fox jumped over The lazy dog.
Array
(
    [The] => The
    [qiuck] => quick
    [jmepud] => jumped
    [oevr] => over
    [the] => The
)

Spell Checking Using Dictionary. Com

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('applemubojumbo');
echo 
$s->getClosestMatch('DictionaryCom') . '<br/>';
echo 
'<br/>';
$s->set('applewqrew');
echo 
$s->getClosestMatch('DictionaryCom') . '<br/>';
echo 
'<br/>';
$s->set('The qiuck fox jmepud oevr the lazy dog.');
echo 
$s->spellEmphasize('DictionaryCom') . '<br/>';
echo 
$s->spellAutoCorrect('DictionaryCom') . '<br/>';

Result:

applemubojumbo

applique

the qiuck fox jmepud oevr the lazy dog.
The quick fox jumped over The lazy dog.

Spell Checking Using Aonaware. Com

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('applemubojumbo');
echo 
$s->getClosestMatch('AonawareCom') . '<br/>';
echo 
'<br/>';
$s->set('applewqrew');
echo 
$s->getClosestMatch('AonawareCom') . '<br/>';
echo 
'<br/>';
$s->set('The qiuck fox jmepud oevr the lazy dog.');
echo 
$s->spellEmphasize('AonawareCom') . '<br/>';
echo 
$s->spellAutoCorrect('AonawareCom') . '<br/>';

Result:

applemubojumbo

applique

the qiuck fox jmepud oevr the lazy dog.
The quick fox jumped over The lazy dog.

02. STRING SIMILIARITY

Soundex

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->soundexPercent('apple') . '% match "apple"<br/>';
echo 
$s->soundexPercent('aple') . '% match "aple"<br/>';
echo 
$s->soundexPercent('aplo') . '% match "aplo"<br/>';
echo 
$s->soundexPercent('epl') . '% match "epl"<br/>';
echo 
$s->soundexPercent('onion') . '% match "onion"<br/>';
echo 
$s->soundexPercent('cabbage') . '% match "cabbage"<br/>';
echo 
$s->soundexPercent('painting') . '% match "painting"<br/>';

Result:

100% match "apple"
100% match "aple"
100% match "aplo"
75% match "epl"
25% match "onion"
50% match "cabbage"
0% match "painting"

Levenshtein

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->levenshtein('apple') . ' operations needed to obtain "apple"<br/>';
echo 
$s->levenshteinPercent('apple') . '% match "apple"<br/>';
echo 
'<br/>';
echo 
$s->levenshtein('aple') . ' operations needed to obtain "aple"<br/>';
echo 
$s->levenshteinPercent('aple') . '% match "aple"<br/>';
echo 
'<br/>';
echo 
$s->levenshtein('aplo') . ' operations needed to obtain "aplo"<br/>';
echo 
$s->levenshteinPercent('aplo') . '% match "aplo"<br/>';
echo 
'<br/>';
echo 
$s->levenshtein('onion') . ' operations needed to obtain "onion"<br/>';
echo 
$s->levenshteinPercent('onion') . '% match "onion"<br/>';

Result:

0 operations needed to obtain "apple"
100% match "apple"

1 operations needed to obtain "aple"
80% match "aple"

2 operations needed to obtain "aplo"
60% match "aplo"

5 operations needed to obtain "onion"
0% match "onion"

Sounds Like

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->soundsLike('apple') ? $s->append(' sounds like "apple"') : $s->append(' does not sound like "apple"'); echo '<br/>';
echo 
$s->soundsLike('aple') ? $s->append(' sounds like "aple"') : $s->append(' does not sound like "aple"'); echo '<br/>';
echo 
$s->soundsLike('epl') ? $s->append(' sounds like "epl"') : $s->append(' does not sound like "epl"'); echo '<br/>';
echo 
$s->soundsLike('epl'70) ? $s->append(' sounds like "epl"') : $s->append(' does not sound like "epl"'); echo '<br/>';

Result:

apple sounds like "apple"
apple sounds like "aple"
apple sounds like "epl"
apple does not sound like "epl"

Match Percent

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->matchPercent('apple') . '% match "apple"<br/>';
echo 
$s->matchPercent('aple') . '% match "aple"<br/>';
echo 
$s->matchPercent('aplo') . '% match "aplo"<br/>';
echo 
$s->matchPercent('epl') . '% match "epl"<br/>';
echo 
$s->matchPercent('onion') . '% match "onion"<br/>';
echo 
$s->matchPercent('cabbage') . '% match "cabbage"<br/>';
echo 
$s->matchPercent('painting'truetruetruetrue) . '% match "painting"<br/>';

Result:

100% match "apple"
92.22% match "aple"
81.67% match "aplo"
57.92% match "epl"
6.25% match "onion"
20.83% match "cabbage"
3.85% match "painting"

Basics

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->soundex() . '<br/>';
echo 
$s->metaphone() . '<br/>';

Result:

A140
APL

Metaphone

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->metaphonePercent('apple') . '% match "apple"<br/>';
echo 
$s->metaphonePercent('aple') . '% match "aple"<br/>';
echo 
$s->metaphonePercent('aplo') . '% match "aplo"<br/>';
echo 
$s->metaphonePercent('epl') . '% match "epl"<br/>';
echo 
$s->metaphonePercent('onion') . '% match "onion"<br/>';
echo 
$s->metaphonePercent('cabbage') . '% match "cabbage"<br/>';
echo 
$s->metaphonePercent('painting') . '% match "painting"<br/>';

Result:

100% match "apple"
100% match "aple"
100% match "aplo"
66.67% match "epl"
0% match "onion"
0% match "cabbage"
0% match "painting"

Intersection

<?php
require_once dirname(__FILE__)."/../../php-advanced-string-classes/bin/wlString.php";
$s = new wlString('apple');
echo 
$s->intersectionPercent('apple') . '% match "apple"<br/>';
echo 
$s->intersectionPercent('aple') . '% match "aple"<br/>';
echo 
$s->intersectionPercent('aplo') . '% match "aplo"<br/>';
echo 
$s->intersectionPercent('epl') . '% match "epl"<br/>';
echo 
$s->intersectionPercent('onion') . '% match "onion"<br/>';
echo 
$s->intersectionPercent('cabbage') . '% match "cabbage"<br/>';
echo 
$s->intersectionPercent('painting') . '% match "painting"<br/>';

Result:

100% match "apple"
88.89% match "aple"
66.67% match "aplo"
50% match "epl"
0% match "onion"
33.33% match "cabbage"
15.38% match "painting"