I am using str_replace to replace a substring of a string however, the replacing happens but the rest of the text is disappearing.
Example of $log_text is %%clinicid=1%% clinic we have five rooms.
function strafter($string, $substring) {
$pos = strpos($string, $substring);
if ($pos === false)
return $string;
else
return(substr($string, $pos+strlen($substring)));
}
$log_text = '%%clinicid=1%% clinic has <b>5</b> rooms.';
if (strpos($log_text, '%%clinicid=') !== false) {
$clinicid = strafter($log_text,'%%clinicid=');
$clean_clinicid = str_replace('%%','',$clinicid);
$clinicname = $db->single("SELECT clinic_name FROM dg_clinics WHERE id = :id", array("id"=>"$clean_clinicid"));
$clinic_id_string = '%%clinicid='.$clinicid;
$log_text = str_replace($clinic_id_string,$clinicname,$log_text);
}
The above code gives
Aaa
only not the full text, instead of
Aaa clinic has 5 rooms.
Where am I doing wrong?
PS. if I use %%clinicid=1%%
it works perfectly but with a string it doesn't work.