I’m having some weird difficulty with removing “\n”‘s from data that is pulled from a database.
The data is an email and gets stored with \n’s throughout it by the system that inputs it.
When I display it, I’ve tried to remove these \n’s using the following:
$htmlbody = str_replace("\n", "", $message['htmlbody']);
or
nl2br($message['htmlbody']);
but both commands still return a string that is full of \n’s.
The variable $message[‘htmlbody’] includes a string like \n\n <div>\n Example Data \n </div>\n, and this data remains the same after being passed through str_replace.
The data originally comes from a JSON webhook which has replaced all the newlines in an HTML email with \n’s. I have control over the data being put into the database as well, and have tried using the above actions on the original data with the same result.
Any thoughts on what might cause this?
Cheers.
If the string you try to modify have
\ndisplayed, and not interpreted as a new line, use :