<?php
$exception = ['will not be '=>'will&nbs;pnot&nbs;pbe ', 'will not ' => 'will&nbs;pnot '];
$string = 'They will not begin';
function f($string, $exception){
$newString = strtr($string, $exception);
$array = explode(' ', $newString);
if( $string !== $newString){
$array = array_combine(array_values($array), array_values($array));
var_dump(array_intersect_key($array, array_flip($exception)));
$array = array_replace($array, array_intersect_key($array, array_flip($exception)));
}
return array_values($array);
}
var_dump(f($string, $exception));
//var_dump(f('Will I love?', $exception));
//var_dump(f('I will love.', $exception));
//var_dump(f('I will not love.', $exception));
//var_dump(f('Do I love?', $exception));
preferences:
38.06 ms | 402 KiB | 5 Q