- array_map: documentation ( source)
- rtrim: documentation ( source)
- explode: documentation ( source)
- in_array: documentation ( source)
- join: documentation ( source)
<?php
$array = array('w','z','u','o','ul.');
$titleOld = 'Testing w it\'s ul. here';
$words = explode(' ', $titleOld);
$titleNew = rtrim(join('', array_map(fn($word) => $word . (in_array($word, $array) ? " " : ' '), $words)));
echo $titleNew; // "Testing w it's ul. here"