explode() not splitting string data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Brent
Forum Newbie
Posts: 4
Joined: Fri Aug 04, 2006 12:09 pm

explode() not splitting string data

Post by Brent »

I am using system('ipconfig', $output) to display the output in a browser window. $output displays as one continuous line since all the line breaks are stripped out so I am trying to break the data back up into a readable format using explode() but it doesn't split the string.

system('ipconfig', $output);
$ipconfig = explode(':',$output);

for($i=0;$i<count($ipconfig);$i++)
{
echo $ipconfig[$i] . "\n";
}


Thanks in advance.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I've been messing with this for 15 minutes now, mainly because I couldn't remember the HTML tag lol.

Code: Select all

<?php
echo '<pre>';
system('ipconfig');
echo '</pre>';
Never used system() before, what a weird function. It actually automatically prints the command results. If you try to set an output var to store the result, it sets the variable to 0.

You can't set a variable to the system() call properly either, as it only stores the last line of the result.

Seems it's impossible to use system() without getting some output.

So the answer to your question is, the output is already on seperate lines, you just couldn't see it because it wasn't proper HTML - check the source ;)
Brent
Forum Newbie
Posts: 4
Joined: Fri Aug 04, 2006 12:09 pm

Post by Brent »

jayshields wrote:I've been messing with this for 15 minutes now, mainly because I couldn't remember the HTML tag lol.

Code: Select all

<?php
echo '<pre>';
system('ipconfig');
echo '</pre>';
Never used system() before, what a weird function. It actually automatically prints the command results. If you try to set an output var to store the result, it sets the variable to 0.

You can't set a variable to the system() call properly either, as it only stores the last line of the result.

Seems it's impossible to use system() without getting some output.

So the answer to your question is, the output is already on seperate lines, you just couldn't see it because it wasn't proper HTML - check the source ;)
You are a lifesaver! Thank you! Works Perfectly! I have been fighting with this for days, Never used '<pre>' before. I was about to resort to redirecting to a txt file and using iframe to display it.
Post Reply