0

I currently have the following php :

<?php
system('/usr/bin/whois 4.2.2.2');
?>

What is the easiest way to replace the newlines with <BR>\n.

Thanks,

5
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by diafol
0

Use nl2br() as @ardav stated. It automatically replace new line character (\n) with html 'br' tag. It prototype looks like:

nl2br(string);

echo nl2br("foo\nbar");    //return foo<br />bar
0

Cool, though it seems to work using strings but it doesnt seem to work when I output the system function to it..

<?php
echo '<pre>';
$output = system('/usr/bin/whois 4.2.2.2');
echo nl2br($output);
echo '</pre>';
?>
0

My question was how do you get nl2br to work with the output of a system command ?

0

Use exec instead of system and specify an empty array as the 2nd variable. This will then be filled with all the lines output by the command.
http://www.php.net/manual/en/function.exec.php

$result = array();
exec('/usr/bin/whois 4.2.2.2', $result);

Now you have an array filled with all the lines, excluding trailing whitespace, of the output.
To print this with <br />'s just use

echo implode("<br />", $result);
0

Use exec instead of system and specify an empty array as the 2nd variable. This will then be filled with all the lines output by the command.
http://www.php.net/manual/en/function.exec.php

$result = array();
exec('/usr/bin/whois 4.2.2.2', $result);

Now you have an array filled with all the lines, excluding trailing whitespace, of the output.
To print this with <br />'s just use

echo implode("<br />", $result);

Perfect .... Many Thanks...

0

mark as solved if so. the link below the box.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.