Source Code is this
Hi Paul
Gina
Emma
John <br />
Source Code is this
Hi Paul
Gina
Emma
John <br />
Try the other version of the code with the counted loop (in in the edited last post on page 1)
I just don't get it! lol.
EDIT: You also might try closing and re-opening your web browser. Sometimes that helps, for some reason. That and refreshing a lot.![]()
--Jas
function GreatMinds(){ return "Think Like Jas"; }
Replaced my script with yours again. Still same output, only this time source code is slightly different.
To be expected though!!!Hi Paul
Martin
David
Sarah<br>
ARGH!!! I am getting frustrated for you, lol. Okay, add this before the loop and tell me what it prints.
If it says 1, we have a problem with preg_split()Code:echo 'There are '.count($names).' names <br>';
if it says 4, there is a problem with the loop.
--Jas
function GreatMinds(){ return "Think Like Jas"; }
lol, I bet I'm more frustrated than you!! But it's nice that you are trying to help so much!!
ok, I added the line you asked, and it's outputted 1!
Question, when you are entering the names in the form, are you entering each name on a newline or are you entering them all on one line? If the latter, then the above should work, but if you are entering each name on a newline, you may want to try something like the following:
Hope this helps.Code:<?php if(isset($_POST['submit'])){ $names = preg_split("/[\n\s,]/",$_POST['names']); foreach ($names as $thename) { echo 'Hi '.$thename.' <br>'; } } else { echo '<form method = "POST" action = "">'; echo '<p>Names</p>'; echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>'; echo '<p><input type="submit" value="Submit" name="submit"></p>'; echo '</form>'; } ?>
"Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design
Brilliant thetestingsite! THAT IS IT! I've been using spaces, and you were probably using breaks lol.
change thistoCode:preg_split("/ /",$POST['names']);or thisCode:preg_split("/\r/",$POST['names']);(depends on your OS)Code:preg_split("/\n/",$POST['names']);
--Jas
function GreatMinds(){ return "Think Like Jas"; }
Well what a prat I feel!! For not mentioning that I'm putting each one on a seperate line!!! That kind of fixed things. If I enter all names on 1 line, with a space in between then it outputs it in the right way. Hi name on each line.
So...
Input....
Paul Gina Emma John
Outputs
Hi Paul
Hi Gina
Hi Emma
Hi John
Now, if I do this....
Paul
Gina
Emma
John
It does this.....
Hi Paul
Hi
Hi Gina
Hi
Hi Emma
Hi
Hi John
lol
No, it's not you. I should of figured. lol
Try this:
should cover all of 'em.Code:if(@preg_match("/\r/",$POST['name'])){ $names = preg_split("/\r/",$POST['names']); }else if(@preg_match("/\n/",$POST['name'])(){ $names = preg_split("/\n/",$POST['names']); }else{ $names = @preg_split("/ /",$POST['names']); }
--Jas
function GreatMinds(){ return "Think Like Jas"; }
Ok, played about with it, found this works the best...
The \s was adding another "hi" inbetween each line!!PHP Code:$names = preg_split("/[\n,]/",$_POST['names']);
Thanks to you both for all your help though.
![]()
Bookmarks