Hello,

I'm currently using the shell_exec command to telnet to a router and grab output. It works fine if I just want to display the output, but I also want to be able to manipulate the data. For example, I want to bold some output, highlight some output in red, and grab some data out of the output (like ip address). In perl I would do the following:

@ = some-command;

for $line (@) {
chomp $line;
if ($line =~ /Protocol/) {
$line = "<b>" . $line . "</b><br>";
}
print $line;
}

In php I'm getting stuck here:

$output = shell_exec('some-command');

I can't figure out how to convert $output to an array. I tried using split to with newline as the separator, but couldn't get that to work. Is there another function I can use, or is there a way to do this with split?

Thank you!

-Laura

    exploding on newlines ought to work (as noted on the split manual page, it's overkill unless you actually need a regular expression); how are you trying it?

    $output = explode("\n", `some-command`);
    foreach($output as $line)
    {
        $line = rtrim($line);
        if(substr($line,0,7)=='Protocol')
            $line = "<b>$line</b><br>";
        echo $line;
    }

      I had no idea I could use backtics within an explode statement!

      That's exactly what I needed - thank you so much for responding.

      🙂

      -Laura

        Write a Reply...