Category: Laravel, Laravel

Here is a short blog for a problem I ran into this evening. I was testing a new endpoint that returns some user data in JSON format.

The old code for getting the initials was using strtoupper and substr like this: public function initials(): string { return strtoupper(substr($this->first_name, 0, 1). But these functions are not multi-byte safe and so they can give incorrect results for multi-byte characters. To solve this we should use the equivalent multi-byte safe functions: public function initials(): string { return mb_strtoupper(mb_substr($this->first_name, 0, 1).
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners