Jump to content

Problem with explode()?


jj20051

Recommended Posts

I have a script that connects to another server to pull data... When it pulls the data it comes back in the following format:

 

t1.sh t2.sh t3.sh test.sh 

 

However using the code bellow does not separate it like it should, it should put one file per line but I think I did something wrong...

 

// Pulls the output from the server:
$var_test = $ssh->exec('./test.sh');
// Explodes it...
$var_test2 = explode(" ", $var_test);
// Echos it one per line...
foreach ($var_test2 as $variable) {
echo '<br>'.$variable;
}

Link to comment
https://forums.phpfreaks.com/topic/252476-problem-with-explode/
Share on other sites

There should be a "<br>" before each file name. I suspect the data is split by new line feeds, not spaces. That could explain the results you're seeing.. try splitting by this instead:

 

preg_split('/(\n|\n\r)/', $var_test);

 

That will use a regular expression to split the string on either "\n" (Linux format line-feed) or "\n\r" (Windows format).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.