<?php
require_once ('mb_trim.php');

$rounds = 1000000;
$nbsp = chr(0xC2).chr(0xA0);
$string = '🛠' . $nbsp . 'äüöödäipusö🛠' . $nbsp . 'öäü';
$toTrim = '🛠öä' . $nbsp . 'ü';

echo 'Zu durchsuchender String (HTML-kodiert:)'. PHP_EOL;
echo "\t". '"' . htmlentities( $string, ENT_HTML5 ) .'"' . PHP_EOL . PHP_EOL;

echo' Zu entfernende Zeichen: (HTML-kodiert:)' . PHP_EOL;
echo "\t". '"' . htmlentities( $toTrim, ENT_HTML5 ) .'"' . PHP_EOL . PHP_EOL;

echo 'Ergebnis für mb_trim(): "'  .  mb_trim( $string, $toTrim ) . '"' . PHP_EOL;
echo 'Ergebnis für mb_rtrim(): "' .  mb_rtrim( $string, $toTrim ) . '"' . PHP_EOL;
echo 'Ergebnis für mb_ltrim(): "' .  mb_ltrim( $string, $toTrim ) . '"' . PHP_EOL;


echo PHP_EOL . 'Zeitmessung:'. PHP_EOL;

####################################################
echo PHP_EOL . 'mb_trim:'  .PHP_EOL;

$start = microtime(true);
for ($i=0; $i<$rounds; $i++) {
	mb_trim( $string, $toTrim ) . PHP_EOL;
}

$time = ( microtime(true) - $start )  ;
echo $time .  PHP_EOL;
echo  round( $time * 1000)  . ' Millisekunden für ' . $rounds . ' Runden. (' . round($time/$rounds * 1000000) . ' Mikrosekunden pro Aufruf).' .  PHP_EOL;

####################################################
echo PHP_EOL . 'mb_rtrim:'  . PHP_EOL;

$start = microtime(true);
for ($i=0; $i<$rounds; $i++) {
	mb_rtrim( $string, $toTrim ) . PHP_EOL;
}

$time = ( microtime(true) - $start )  ;
echo $time .  PHP_EOL;
echo  round( $time * 1000)  . ' Millisekunden für ' . $rounds . ' Runden. (' . round($time/$rounds * 1000000) . ' Mikrosekunden pro Aufruf).' .  PHP_EOL;

####################################################
echo PHP_EOL . 'mb_ltrim:'  . PHP_EOL;
$start = microtime(true);
for ($i=0; $i<$rounds; $i++) {
	mb_ltrim( $string, $toTrim ) . PHP_EOL;
}

$time = ( microtime(true) - $start )  ;
echo $time .  PHP_EOL;
echo  round( $time * 1000)  . ' Millisekunden für ' . $rounds . ' Runden. (' . round($time/$rounds * 1000000) . ' Mikrosekunden pro Aufruf).' .  PHP_EOL;
