PHP code example of nox7 / multibyte-strings

1. Go to this page and download the library: Download nox7/multibyte-strings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nox7 / multibyte-strings example snippets




$string = <<<HTML
    <title>♥ Love Your Home’s Pipes! Best Plumbing Around!</title>
HTML;

$multibyte = new MultiByteString($string);
$matches = $multibyte->findAllOccurrences("Plumbing");

// The $matches array is the same array result you would get from preg_match_all with the OFFSET flag used.
// This library corrects the string positions for you.
print("The first occurrence of {$matches[0][0]} starts at character {$matches[0][1]}");



$string = <<<HTML
    <title>♥ Love Your Home’s Pipes! Best Plumbing Around!</title>
HTML;

$query = "Plumbing";
$multibyte = new MultiByteString($string);
$matches = $multibyte->findAllOccurrences($query);
$firstMatch = $matches[0];
$multibyteLengthOfQuery = mb_strlen($query);

$stubResult = $multibyte->getSubStringWithPadding(
    start: $firstMatch[1],
    stubMultiByteLength: $multibyteLengthOfQuery,
    padding: 35,
);

// $stubResult is an instance of MultibyteStrings\StubResult
printf("Before: {$stubResult->beforeStub}\nStub: {$stubResult->stub}\nAfter: {$stubResult->afterStub}");