Jump to content

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).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.