Jump to content
  • Advertisement
Sign in to follow this  
dead1ock

[web] ob_get_clean() problems.

This topic is 2555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!