Re: foreach question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Quoting Lori Lay <llay@xxxxxxxxxxxxxxxxxxx>:

> chris@xxxxxxxxxxxx wrote:
> > Sorry this is the full script...
> >
> > whois.php
> >
> > <html>
> > <body><span style="font-size:13;font-family:Arial,Verdana;">
> > <form method='POST' action='whois.php'>
> >
> > <p><b>Enter Domain Names (one per line)</b></p>
> > <textarea name='domain' cols="50" rows="8" 
> > style="font-size:13;font-family:Arial,Verdana;"></textarea><p>
> 
> Gotcha!  A textarea does not produce an array.  Even though the user 
> should be separating the lines with a line break, this turns into one 
> long string with line breaks in it, not separate array elements.  You 
> will have to do this manually.  Actually, you could probably use nl2br 
> to insert BR's before the line breaks (it doesn't replace them, but 
> that's usually good enough).
> 
> Lori


much better, it all makes sense now. This is what I would do:

<?php
$array = split("\n", $_POST['domain']);
foreach( $array as $key ) {
    echo "$key<br>";
}
?>


Siavash


> >
> > <input type='submit' value="Submit Domain Query">
> > </form>
> > <p><b><u>Whois Results:</u></b></p>
> >
> > <?php
> >
> > foreach( $_POST as $key ) {
> >    echo "$key<br>";
> > }
> > ?>
> >
> > </body>
> > </html>
> >
> > ----- Original Message ----- From: "Lori Lay" <llay@xxxxxxxxxxxxxxxxxxx>
> > To: <chris@xxxxxxxxxxxx>
> > Cc: <php-general@xxxxxxxxxxxxx>
> > Sent: Monday, April 09, 2007 5:20 AM
> > Subject: Re:  foreach question
> >
> >
> >> chris@xxxxxxxxxxxx wrote:
> >>> "both examples do the same thing.."
> >>>
> >>> no, ex1 only has 1 <br />
> >>>
> >>> so outputs like..
> >>> item1item2item3item4item5<br />
> >>>
> >>> Where as I want this..
> >>>
> >>> item1<br />
> >>> item2<br />
> >>> item3<br />
> >>> item4<br />
> >>> item5<br />
> >>>
> >>> ie a line break after every item.
> >>>
> >> Silly question, perhaps, but are you sure $_POST is an array (with 5 
> >> elements)?  What you have written should produce a break after each 
> >> item if POST is a 5 element array.  However if POST is a single 
> >> element with the five items concatenated together, then they would be 
> >> printed the way you have it listed above...
> >>
> >> It might be better to post the full script to the list.
> >>
> >> Lori
> >>>
> >>> ----- Original Message ----- From: "Sebe" <sebastian@xxxxxxxx>
> >>> To: <chris@xxxxxxxxxxxx>
> >>> Cc: <php-general@xxxxxxxxxxxxx>
> >>> Sent: Monday, April 09, 2007 1:22 AM
> >>> Subject: Re:  foreach question
> >>>
> >>>
> >>>> chris@xxxxxxxxxxxx wrote:
> >>>>> I have ..
> >>>>>
> >>>>> foreach( $_POST as $key ) {    echo "$key<br />";
> >>>>> }
> >>>>>
> >>>>> and that gives me
> >>>>>
> >>>>> item1
> >>>>> item2
> >>>>> item3
> >>>>> item4
> >>>>> item5<br />
> >>>>>
> >>>>> how do I write it to give me
> >>>>>
> >>>>> item1<br />
> >>>>> item2<br />
> >>>>> item3<br />
> >>>>> item4<br />
> >>>>> item5<br />
> >>>>>
> >>>>> Thanks
> >>>>>
> >>>> both examples do the same thing..
> >>>>
> >>>> -- 
> >>>> PHP General Mailing List (http://www.php.net/)
> >>>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>>
> >>>>
> >>>>
> >>>
> >>
> >> -- 
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> >>
> >
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux