I am testing the str_replace in phpList and I want to replace the first match of a string. I found on other posts that I should use preg_replace if I want to replace the first match of a string, the problem is preg_replace does not return a string for some reason.
Both
$fp = fopen('/var/www/data.txt', 'w');
$string_test = preg_replace(basename($html_images[$i]), "cid:$cid", $this->Body,1);
fwrite($fp,$string_test);
fclose($fp);
and
$fp = fopen('/var/www/data.txt', 'w');
fwrite($fp,preg_replace(basename($html_images[$i]), "cid:$cid", $this->Body,1));
fclose($fp);
writes an empty string to the file. I would like to know how to get a return string and str_replace does not seem to work with first match. However, str_replace would return a string.