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,317
  • 2
  • 23
  • 38
Professor Haseeb
  • 81
  • 1
  • 2
  • 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
  • 30,622
  • 5
  • 73
  • 66
2
echo nl2br(json_decode($response));
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
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
  • 10