DReade83
asked on
str_replace Question
I want to get the following line to work:
$text = str_replace("", "No Information", $text);
Basically, I want it to replace a blank answer with "No Information". Unfortunately when I insert this, it doesn't work. I've tried replacing the "" with NULL, 0 and "0", but neither work.
Can anyone help? Thanks in advance.
$text = str_replace("", "No Information", $text);
Basically, I want it to replace a blank answer with "No Information". Unfortunately when I insert this, it doesn't work. I've tried replacing the "" with NULL, 0 and "0", but neither work.
Can anyone help? Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much!!! Works a treat! :-D
ASKER
Sorry, posted too soon. The first answer worked no probs. Thanks again.
Or you could condense it to one line like this:
$text = (strlen(trim($text))>0 || !is_null($text)) ? str_replace("", "No Information", $text) : "No Information";
Thanks for the points.
$text = (strlen(trim($text))>0 || !is_null($text)) ? str_replace("", "No Information", $text) : "No Information";
Thanks for the points.
if (strlen(trim($text))>0 || !is_null($text)) {
$text = str_replace("", "No Information", $text);
} else {
$text = "No Information";
}