PHP code example of alexeyyashin / estring
1. Go to this page and download the library: Download alexeyyashin/estring 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/ */
alexeyyashin / estring example snippets
$first = ' Some string to operate';
// PHP functions
$second = $first;
if (strpos(strtolower(trim($second)), 'some') === 0) {
echo str_replace('Some', 'Awesome', trim($second)) . "\n";
echo "found\n";
} elseif (substr(strtolower(trim($second)), - strlen('operate')) === 'operate') {
echo str_replace('operate', 'control', trim($second)) . "\n";
echo "found but ending\n";
}
// Same with estring
$third = estring($first);
if ($third->trim()->startsWith('some', true)) {
echo $third->trim()->replace(['Some' => 'Awesome']) . "\n";
echo "found\n";
} elseif ($third->trim()->endsWith('operate')) {
echo $third->trim()->replace(['operate' => 'control']) . "\n";
echo "found but ending\n";
}