There's already a function for this:
```php
Loader::helper('text')->specialchars(...);
```