Level 28
$new = substr($old, 0, 1) . " " . chunk_split(substr($old, 1), 3, ' ');
Not pretty though :D
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, In the string I would like to add a spacer after the first character, and then every next 3 characters. I tried something like this, but this code adds spaces every 3 characters:
chunk_split($string, 3, ' ');
Please or to participate in this conversation.