0

I'm trying to echo a string and the string contains "\n" and "\r" in it, but when it executes it still shows the "\n" and "\r".

Here is what I'm doing.

$url = 'http://whoiz.herokuapp.com/lookup.json?url=madithouse.com';
$response = file_get_contents($url);
echo $response;

It echos every thing as it is, all I want is that everywhere where it has "\n" it goes to new line.

AeroX
  • 3,387
  • 2
  • 25
  • 39
Professor Haseeb
  • 111
  • 1
  • 3
  • 11

3 Answers3

3

If you're outputting to a browser you won't see the new lines (unless you view source). You'd have to use nl2br().

Bill Criswell
  • 32,161
  • 7
  • 75
  • 66
2
echo nl2br(json_decode($response));
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

In this case nl2br() doesn't work. If you want output in new line in place of "\n" just replace it with <br>.

Like this

$url = 'http://whoiz.herokuapp.com/lookup.json?url=madithouse.com';

$response = file_get_contents($url);

echo str_replace("\\n", "<br>", $response);
Jahanzeb
  • 613
  • 4
  • 11