How can a space be inserted at the 3rd position of a 9-character long text string in PHP?

To insert a space at the 3rd position of a 9-character long text string in PHP, you can use the substr_replace() function to insert the space at the desired position. The substr_replace() function allows you to replace a portion of a string with another string starting at a specified position.

$text = "abcdefghi";
$text = substr_replace($text, ' ', 2, 0);
echo $text; // Output: "ab cdefghi"