Shouldn't this work?

```php
return preg_replace_callback(
    '/[^' . implode('', $markers) . ']+/',
    function($matches) {
        return ucfirst($matches[0]);
    },
    $string
);
```

That should cut down on the characters in the markers array as well: `\A` for instance.