str_replace() does not have the capability to limit the number of replacements. preg_replace() though not necesary for finding your needle in the haystack string DOES allow replacement limiting. Using explode() is not a horrible approach, but you should limit the explosions to 2 if you use it. I do not like the indirect-ness of generating a temporary array when a string result is sought.
Code: (Demo)
$strOne = "Place new content here: , but not past the commma.";
$strTwo = "test content";
echo preg_replace('/,/', "$strTwo,", $strOne, 1);
You could use preg_replace('/(?=,)/', $strTwo, $strOne, 1) to avoid mentioning the needle in the replacement string, but that regex will perform worse because the lookahead will be performed on every step while traversing the haystring string -- not great.
If your needle string might contain characters that have special meaning to the regex engine, then use '/' . preg_quote($yourNeedle, '/') . '/' as your pattern.
If your needle is more variable, then use the same regex technique. If wanting to find the first hashtag substring in a block of text, merely search for the first occurring # followed by one (or more) word character(s). If you want to enforce that the # is preceded by a space, you can add that too. You can use a lookahead to avoid copying the needle into the replacement parameter but this might execute a little slower depending on the quality of the haystack string.
Input:
$strOne = "Programming requires life long learning #learning #stackoverflow #programming";
$strTwo = "\n\n";
Code: (Demo)
echo preg_replace('/#\w/', "$strTwo$0", $strOne, 1);
// or echo preg_replace('/ (#\w)/', "$strTwo$1", $strOne, 1); // to replace the preceding space with 2 newlines
Or: (Demo)
echo preg_replace('/ \K(?=#\w)/', $strTwo, $strOne, 1);