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

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
jcrook
Forum Newbie
Posts: 4
Joined: Sun Feb 20, 2005 11:01 am

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

Post 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]
Last edited by jcrook on Sun Feb 20, 2005 12:55 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
jcrook
Forum Newbie
Posts: 4
Joined: Sun Feb 20, 2005 11:01 am

Post 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.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post 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>";
?>
jcrook
Forum Newbie
Posts: 4
Joined: Sun Feb 20, 2005 11:01 am

Post 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
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Um... Did you try the code that I posted? It ought to be doing what you want.
jcrook
Forum Newbie
Posts: 4
Joined: Sun Feb 20, 2005 11:01 am

Post by jcrook »

Sorry smpdawg, I missed a . in one of the lines. That did the trick. Thank you ver much.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

No problem.
Post Reply