Page 1 of 1

[SOLVED]contents of an array to a single line in a text file

Posted: Sun Feb 20, 2005 11:50 am
by jcrook
I am trying to echo the contents of an array to a textfile so I can dynamically generate shell scripts. Any help with this would be very much appreciated.

Code: Select all

<?
   $nodes1 = ($HTTP_POST_VARS&#1111;"nodes"]);
   include 'db1.php';
   foreach ($nodes1 as $node1) &#123;
         $add = ("-a add_member=$node1 ");
         if ($submit) &#123;
            exec("echo $con $nim nim -o define -t mac_group $add $group >> /tmp/test/loadaix");
            &#125;
     &#125;
   include 'style.php';
   echo "<table border="0" cellpadding="0" cellspacing="0" width="90%"
align="center">
   <tr>
   <td align="left"><strong><font color="#FFFFFF">$group has been created!</font></strong></td>
   </tr>
   </table>";
?>
PHENOM | PLEASE USE

Code: Select all

TAGS NEXT TIME[/size][/color]

Posted: Sun Feb 20, 2005 12:03 pm
by John Cartwright
Firstly, your script register_globals to be ON which by default it is off. Secondly, what is the output? Any errors?

try error_reporting(E_ALL); at the top of your script

Posted: Sun Feb 20, 2005 12:14 pm
by jcrook
I have register_globals=On in my php.ini file. The script works except for the tha fact the it will echo every instance of $node1 on a seperate line in the text file.

Posted: Sun Feb 20, 2005 12:21 pm
by smpdawg
Are you meaning to do something like this?

Code: Select all

<?php
   $nodes1 = ($HTTP_POST_VARS&#1111;"nodes"]);
   include 'db1.php';
   $add = "";
   foreach ($nodes1 as $node1) &#123;
     $add .= "-a add_member=$node1 ";
   &#125;
   if ($submit) &#123;
     exec("echo $con $nim nim -o define -t mac_group $add $group >> /tmp/test/loadaix");
   &#125;
     
   include 'style.php';
   echo "<table border="0" cellpadding="0" cellspacing="0" width="90%"
align="center">
   <tr>
   <td align="left"><strong><font color="#FFFFFF">$group has been created!</font></strong></td>
   </tr>
   </table>";
?>

Posted: Sun Feb 20, 2005 12:32 pm
by jcrook
What the script produces now is :

rsh 10.2.1.102 nim -o define -t mac_group -a add_member=test3 nim-group
rsh 10.2.1.102 nim -o define -t mac_group -a add_member=test6 nim-group
rsh 10.2.1.102 nim -o define -t mac_group -a add_member=test10 nim-group
rsh 10.2.1.102 nim -o define -t mac_group -a add_member=test11 nim-group


What I am trying to get it to produce is:

rsh 10.2.1.102 nim -o define -t mac_group -a add_member=test3 -a add_member=test6 -a add_member=test10 -a add_member=test11 nim-group

Posted: Sun Feb 20, 2005 12:44 pm
by smpdawg
Um... Did you try the code that I posted? It ought to be doing what you want.

Posted: Sun Feb 20, 2005 12:51 pm
by jcrook
Sorry smpdawg, I missed a . in one of the lines. That did the trick. Thank you ver much.

Posted: Sun Feb 20, 2005 12:52 pm
by smpdawg
No problem.