I have this code
if($hgroup['groupid'] == $row_groups['groupid']){
$problem++;
$hostname=DBfetch($cursor_gethost_again);
$replace_macro=array('/{HOSTNAME}/','/{HOST.NAME}/');
$problem_text=$problem_text.$trigger['description'];
$problem_text=preg_replace($replace_macro,$hostname['name'],$problem_text);
$problem_text=$problem_text."\r\n";
}
It is a code generating in cycle. Can anybody help me how to make that stupid newline? I have to do it this way because I’m modifying one code. So I want to keep that layout.
It doesn’t work. It will print it with text. I also try preg_replace to <br />.
If you’re trying to print out HTML, the new line is not using
\r\nbut by appending<br/>.In a comment you confirmed that you were trying to view this in a browser. As Kolink said, browsers collapse whitespaces to a space, so you lose your new line information.
If you were to output the value to a standard output, like the console, then
\r\nare the solution. Same thing if you are dealing with a file you want to write to.If you wanted to output it both to a standard output AND then in HTML, I’d suggest first filling it with
\r\n, output your variable, then usestr_replace(documentation here) to convert all your\r\nto<br/>: