I'm using str_replace() PHP function which doesn't replace empty string.
Is it possible to replace it using some other PHP functions?
Here is my code:
$var = "text1|text2";
$expn = explode("|", $var);
$new = "new text";
str_replace($expn[1], $new, $var);
This code really works, but if the second value is empty it doesn't:
$var = "text1|";
$expn = explode("|", $var);
$new = "new text";
str_replace($expn[1], $new, $var);
I want this to echo text1|new text but it doesnt. In the first case it does without a problem. I want this to be changed anyway, it doesn't depend if it's empty or not.
Thanks in advance.