[web] ob_get_clean() problems.

Started by
0 comments, last by benryves 12 years, 9 months ago
I am trying to create a function that grabs a script file and executes the output on a telnet device. I have it working, but ob_get_clean() seems to be removing any newlines after a php closing brace ( i.e. ?> ). Has anyone encountered this problem?

PHP


public final function execScript($name, $args)
{
ob_start();
include("../apps/frontend/modules/device/scripts/" . $name . ".php");
$partial = ob_get_clean();
$commands = explode("\n", $partial);

foreach($commands as $command)
{
$output .= $this->telnet->exec($command);
}

return $output;
}


"Script"


conf
int ethernet 1/<?php echo $args['port']; ?>
switchport allowed vlan add <?php echo $args['vlan_id']; ?> tagged
switchport native vlan <?php echo $args['vlan_id']; ?>
switchport allowed vlan remove 1
end


Expected Output


conf
int ethernet 1/18
switchport allowed vlan add 100 tagged
switchport native vlan 100
switchport allowed vlan remove 1
end


Actual Output


conf
int ethernet 1/18switchport allowed vlan add 100 tagged
switchport native vlan 100switchport allowed vlan remove 1
end
Advertisement
This is not a problem with ob_get_clean but a "feature" to prevent files containing only PHP code from sending an accidental newline to the browser at the end of the file. According to the manual:

The closing tag for the block will include the immediately trailing newline if one is present.[/quote]

You will need to insert an additional newline to compensate for this.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

This topic is closed to new replies.

Advertisement