Log in

View Full Version : More than one input to a form question - how to process?



smithster
12-14-2007, 06:06 PM
<?php

if(isset($_POST['submit'])){

$names = array($_POST['names']);

foreach($names as $value)
{
echo 'Hi '.$value.' <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>';
}
?>


the user is asked to enter some names (just for this example) and they can enter as many as they like.

Example....
Input - Paul Gina Emma John

Output....


Hi Paul Gina Emma John


But...

What I want is the following...


Hi Paul
Hi Gina
Hi Emma
Hi John


I have a perfectly good reason for wanting to know how to do this. I don't often post real scripts anymore as I found myself just relying on others to fix the script and then I wouldn't learn anything. So I think up an example to use which needs fixing and then I learn from that!!

Hoping someone can spot the mistake here and can help me to fix this.

Thanks in advance.

Smithster.

Jas
12-14-2007, 06:12 PM
Try


if(isset($_POST['submit'])){

$names = preg_split("/ /",$_POST['names']);

foreach($names as $value)
{
echo 'Hi '.$value.' <br />';
}
}

or I thing explode() would work too.

smithster
12-14-2007, 06:15 PM
Thanks Jas, unfortunately it just gives the same output. Hi once, with all names on the same line.

Jas
12-14-2007, 06:17 PM
Are you sure? It just worked for me. Your code gave the error you described, but mine output

Hi dave
Hi joe
Hi john
Try pasting this:

<?php

if(isset($_POST['submit'])){

$names = preg_split("/ /",$_POST['names']);

foreach($names as $value)
{
echo 'Hi '.$value.' <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>';
}
?>

smithster
12-14-2007, 06:26 PM
lol that is very strange! It is still doing exactly the same thing for me!! I even tried changing the file name to see if it was a refresh problem. Still outputs it in the same way for me!! All on one line!!

Tried it again on another webserver, same output also. :|

Jas
12-14-2007, 06:30 PM
Post your code, maybe there is a typo. . . unlikely if you pasted it, but might as well check. This is very stange. What version of PHP? It is PHP 5, right?

smithster
12-14-2007, 06:33 PM
well, it's PHP5.22 on my local web server, but where the real thing is to be hosted, that is 4.44.



<?php

if(isset($_POST['submit'])){

$names = preg_split("/ /",$_POST['names']);

foreach($names as $value)

{
echo 'Hi '.$value.' <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>';
}
?>


Coppied and pasted so yes unlikely!! But it does happen!!

Jas
12-14-2007, 06:35 PM
Are you running this script on PHP5 or PHP4?

smithster
12-14-2007, 06:37 PM
All testing is done on local webserver which runs PHP 5.22

Having said that, any script I have ever written on local server, then uploaded to online server, even with different versions of PHP, I have never had compatibility issues.

Jas
12-14-2007, 06:38 PM
Okay, it's not the PHP parser. Maybe the browser? Try another one and check the generated source code.

EDIT: or try this code:

<?php

if(isset($_POST['submit'])){

$names = preg_split("/ /",$_POST['names']);

for($i=0; $i<count($names); $i++)
{
echo 'Hi '.$names[$i].' <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>';
}
?>

smithster
12-14-2007, 06:42 PM
Source Code is this



Hi Paul
Gina
Emma
John <br />

Jas
12-14-2007, 06:45 PM
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. :)

smithster
12-14-2007, 06:51 PM
Replaced my script with yours again. Still same output, only this time source code is slightly different.



Hi Paul
Martin
David
Sarah<br>

To be expected though!!!

Jas
12-14-2007, 07:03 PM
ARGH!!! I am getting frustrated for you, lol. Okay, add this before the loop and tell me what it prints.

echo 'There are '.count($names).' names <br>';
If it says 1, we have a problem with preg_split()
if it says 4, there is a problem with the loop.

smithster
12-14-2007, 07:17 PM
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!

thetestingsite
12-14-2007, 07:26 PM
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:



<?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>';
}
?>


Hope this helps.

Jas
12-14-2007, 07:29 PM
Brilliant thetestingsite! THAT IS IT! I've been using spaces, and you were probably using breaks lol.
change this
preg_split("/ /",$POST['names']);to
preg_split("/\r/",$POST['names']);
or this
preg_split("/\n/",$POST['names']);
(depends on your OS)

smithster
12-14-2007, 07:32 PM
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

Jas
12-14-2007, 07:37 PM
No, it's not you. I should of figured. lol :p
Try this:


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']);
}


should cover all of 'em.

smithster
12-14-2007, 07:40 PM
Ok, played about with it, found this works the best...


$names = preg_split("/[\n,]/",$_POST['names']);


The \s was adding another "hi" inbetween each line!!

Thanks to you both for all your help though.
:)

smithster
12-14-2007, 07:48 PM
Finished script just incase it's needed.


<?php

if(isset($_POST['submit'])){

if(@preg_match("/\r/",$_POST['names']))
{
$names = preg_split("/\r/",$_POST['names']);
}
else if(@preg_match("/\n/",$_POST['names']))
{
$names = preg_split("/\n/",$_POST['names']);
}
else
{
$names = @preg_split("/ /",$_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>';
}
?>

Jas
12-14-2007, 07:55 PM
Great work! By the way, what is the difference between \n and the [\n,] that you had? :confused: I don't use preg function very much, so I don't really know much about that stuff.

smithster
12-14-2007, 09:04 PM
ok, next part of this! I thought I'd be ok from here but no!! What if I wanted to pair off a username with a password like this.....

user1 : pass1
user2 : pass2
user3 : pass3
and so on...... (without spaces though as : and p together gives a :p lol)

I thought this would be ok...


foreach ($usernames as $users && $passwords as $pass){

Output....


Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ')'


Also tried...


foreach ($usernames as $users || $passwords as $pass){
and also
foreach ($usernames as $users) && ($passwords as $pass){

All give the same error.

Any ideas?

Thanks again,

Smithster.

edit......

almost got it. Slight output problem though....


foreach ($usernames as $users){
foreach ($passwords as $pass){
$contentusers = ''.$users.':'.$pass.'<br>';
echo $contentusers;
}
}



user1 : pass1
user1 : pass2
user1 : pass3
user1 : pass4
user2 : pass1
user2 : pass2
user2 : pass3
user2 : pass4
user3 : pass1
user3 : pass2
user3 : pass3
user3 : pass4
user4 : pass1
user4 : pass2
user4 : pass3
user4 : pass4

Jas
12-14-2007, 09:39 PM
I don't have access to my WAMP server, so I can't test this. But try it:

<?php

if(isset($_POST['submit'])){

if(@preg_match("/\r/",$_POST['names']))
{
$names = preg_split("/\r/",$_POST['names']);
}
else if(@preg_match("/\n/",$_POST['names']))
{
$names = preg_split("/\n/",$_POST['names']);
}

foreach ($names as $thename) {
$info = preg_split("/:/",$thename);
echo "Name: ".$info[0]." Password: ".$info[1].'<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>';
}
?>

This is the easiest way I can think of, and it is the closest to your original code.

EDIT: Make sure you get the right one. . . I edited it (had a wrong var name)
I'm not sure if this is what your looking for, but it should work. . .

smithster
12-14-2007, 09:54 PM
This isn't going to work.

Here's the script updated with yours added in.


<?php

if(isset($_POST['submit'])){

if(@preg_match("/\r/",$_POST['names']))
{
$names = preg_split("/\r/",$_POST['names']);
}
else if(@preg_match("/\n/",$_POST['names']))
{
$names = preg_split("/\n/",$_POST['names']);
}
if(@preg_match("/\r/",$_POST['passwords']))
{
$passwords = preg_split("/\r/",$_POST['passwords']);
}
else if(@preg_match("/\n/",$_POST['passwords']))
{
$passwords = preg_split("/\n/",$_POST['passwords']);
}

foreach ($names as $thename) {
$info = preg_split("/:/",$thename);
echo "Name: ".$info[0]." Password: ".$info[1].'<br>';
}
}
else
{
echo '<form method = "POST" action = "">';
echo '<p>Names</p>';
echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
echo '<p>Passwords</p>';
echo '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
echo '<p><input type="submit" value="Submit" name="submit"></p>';
echo '</form>';
}
?>

Output....


Name: paul Password:
Name: smith Password:
Name: emma Password:
Name: john Password:

There isn't anything telling it what to do with the passwords and that's the part I'm struggling with.

Jas
12-14-2007, 10:04 PM
I didn't know what your form looked like. My way was in the names text box you typed Name:Password. Like Jim:jim99 and the output would be Name: Jim Password: jim99 (in other words you don't need the pw box)

EDIT: Hang on and I'll code it your way :)


<?php

if(isset($_POST['submit'])){

if(@preg_match("/\r/",$_POST['names']))
{
$names = preg_split("/\r/",$_POST['names']);
}
else if(@preg_match("/\n/",$_POST['names']))
{
$names = preg_split("/\n/",$_POST['names']);
}
if(@preg_match("/\r/",$_POST['passwords']))
{
$passwords = preg_split("/\r/",$_POST['passwords']);
}
else if(@preg_match("/\n/",$_POST['passwords']))
{
$passwords = preg_split("/\n/",$_POST['passwords']);
}

for($i=0; $i<count($names) || $i<count($passwords);$i++){
echo "Name: ".$names[$i]." Password: ".$passwords[$i];
}
}
else
{
echo '<form method = "POST" action = "">';
echo '<p>Names</p>';
echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
echo '<p>Passwords</p>';
echo '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
echo '<p><input type="submit" value="Submit" name="submit"></p>';
echo '</form>';
}
?>

Try that. Your way had a loop within a loop. This is one loop that does both at the same time.

smithster
12-14-2007, 10:22 PM
Thank you Jas, getting there now!! :)

Changed it slightly to output each one on a new line.


for($i=0; $i<count($names) || $i<count($passwords);$i++){
echo ''.$names[$i].':'.$passwords[$i].'<br>';
}

Problem!
The output...


user1:pass1
user2: pass2
user3: pass3
user4: pass4


The phpcode under output is actually supposed to be a quote, but it puts a : and the p together to make emoticons!!!

For some reason, the 1st 1 is correct as I want it. But the rest all have a space between the : and the password. Why is this?

Jas
12-14-2007, 10:28 PM
EDIT: try
echo "Name: ".preg_replace("/ /","",$names[$i])." Password: ".preg_replace("/ /","",$passwords[$i]);


EDIT 2: You might also try:
echo "Name: ".preg_replace("/ /","",$names[$i],1)." Password: ".preg_replace("/ /","",$passwords[$i],1);
//The 1 at the end makes sure only the first space is removed. Might me advantageous, may not be.


EDIT 3: Better idea! Try this:

if(@preg_match("/\r/",$_POST['names']))
{
$names = preg_split("/\r /",$_POST['names']);
}
else if(@preg_match("/\n /",$_POST['names']))
{
$names = preg_split("/\n /",$_POST['names']);
}
if(@preg_match("/\r /",$_POST['passwords']))
{
$passwords = preg_split("/\r /",$_POST['passwords']);
}
else if(@preg_match("/\n /",$_POST['passwords']))
{
$passwords = preg_split("/\n /",$_POST['passwords']);
}

smithster
12-14-2007, 10:36 PM
Still exactly the same output.

On both of them. 1st is perfect. Anything after that has a space before the password and there shouldn't be!!!

Jas
12-14-2007, 10:40 PM
Hmm. . . I am away from wamp right now, so it's hard to figure out lol. Try the last edit I made on my previous post. Probably won't work though. I might have to look at it later. It must be from the \n or \r because it doesn't effect the first. You could try:

echo "Name: ".preg_replace("/\n/","",$names[$i])." Password: ".preg_replace("/\n/","",$passwords[$i]);
If that works I can give you a more effective solution later :)

smithster
12-14-2007, 10:46 PM
lol, well the 3rd edit killed it!! Outputs all on 1 line again now!! Also, no passwords output at all!!!

Didn't realise you wern't able to test this out. No worries if you want to look at it later.

I Appreciate the time you have spent on this one anyway. :p

Jas
12-14-2007, 10:55 PM
It's no problem at all. My college finals are over, and this is kinda fun (I know, my life is sad). But yeah, I'll look at it tonight if that's okay. Good luck! Maybe you can fix it before me. If yuo can't, I think I had that problem with a script I wrote a while back and I might be able to dig up my solution if I need to-- it's at home of course :p

EDIT: BTW did this work:
echo "Name: ".preg_replace("/\n/","",$names[$i])." Password: ".preg_replace("/\n/","",$passwords[$i]);

smithster
12-14-2007, 11:00 PM
lol, hey, people can say what they want!! I been doing this for around a year now. Still a noob I know!! But I'm learning, and enjoying what I'm getting out of it. But this is why I don't post the real scripts so that I can learn by using examples like this. The actual script itself will be used to auto write a .htaccess file and a .htpasswd file for a user upon request.

Anyway, no worries, I'll keep knocking my head on the desk in the hope I might spot the problem!! I'm not well experienced though with any of the preg commands. But we'll see what happens.

Thanks again. :p

Smithster.

Jas
12-15-2007, 04:33 AM
This code worked for me. Produced
Joey:joey101
Bobby:bobby99
Mike:mikes-the-man

Here it is:

<?php

if(isset($_POST['submit'])){

if(@preg_match("/\r/",$_POST['names'])){
$names = preg_split("/\r/",$_POST['names']);
$passwords = preg_split("/\r/",$_POST['passwords']);
}else if(@preg_match("/\n/",$_POST['names'])){
$names = preg_split("/\n/",$_POST['names']);
$passwords = preg_split("/\n/",$_POST['passwords']);
}

for($i=0; $i<count($names) || $i<count($passwords);$i++){
echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.preg_replace('/[\r\n]/','',$passwords[$i]).'<br>';
}

}else{
echo '<form method = "POST" action = "">';
echo '<p>Names</p>';
echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
echo '<p>Passwords</p>';
echo '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
echo '<p><input type="submit" value="Submit" name="submit"></p>';
echo '</form>';
}
?>

smithster
12-15-2007, 04:44 PM
Sorry for long reply. Been at work all day. Thanks for building this up for me. Works very well. Except for 1 thing!! If a user only puts in 1 username and password, the output is only the first letter of each word.

e.g.

output is
e:s

Also, next part I am trying to do is encode the password.


$passwd = crypt($passwords, base64_encode($passwords));

That's the command used to encode passwords suitable for .htaccess. I tried to put it into the script but it's throwing errors out at me.

Any ideas on both of the above?

Thanks again for all your help with this.

Smithster.

Jas
12-15-2007, 06:47 PM
Here is the fix to the old script:

<?php

if(isset($_POST['submit'])){

$names = array();
$passwords = array();

if(@preg_match("/\r/",$_POST['names'])){
$names = preg_split("/\r/",$_POST['names']);
$passwords = preg_split("/\r/",$_POST['passwords']);
}else if(@preg_match("/\n/",$_POST['names'])){
$names = preg_split("/\n/",$_POST['names']);
$passwords = preg_split("/\n/",$_POST['passwords']);
}else{
$names[] = $_POST['names'];
$passwords[] = $_POST['passwords'];
}

for($i=0; $i<count($names) || $i<count($passwords);$i++){
echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.preg_replace('/[\r\n]/','',$passwords[$i]).'<br>';
}

}else{
echo '<form method = "POST" action = "">';
echo '<p>Names</p>';
echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>';
echo '<p>Passwords</p>';
echo '<p><textarea rows="10" name="passwords" cols="37"></textarea></p>';
echo '<p><input type="submit" value="Submit" name="submit"></p>';
echo '</form>';
}
?>
The problem was that it thought, since there were no breaks, that the string was an array. So, char 1 was element 1. Interesting error, and a good catch by you.
I'll get the crypt in a moment. :)

smithster
12-15-2007, 07:02 PM
Nice one Jas, really does work well now :)

Thanks again.

Jas
12-15-2007, 07:23 PM
That's why I got an "A" in my programing class ;), lol. Here is what you might do for encryption:

for($i=0; $i<count($names) || $i<count($passwords);$i++){
echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),CRYPT_EXT_DES).'<br>';
}

Let me know if that works. Now, you should not only use that. You should also get creative and encrypt it in other ways-- no one should know how your process of encryption works. One thing you can do in use preg_replace() to replace letters, and then do the crypt function again.

Also, how are you going to unencrypt it if your using htaccess?

smithster
12-15-2007, 09:27 PM
Nice one, really wish they taught it at my school. But they didn't. Left college not knowing anything about html let alone PHP. Have had to learn it all by myself really. And with the help of forums too. Used to leach scripts off others but then decided it wasn't nice and I should try to create my own!!

Your coding there almost worked but had to change the encription method to mine.

.htaccess files apparently use one type of encription. So I've heard. I don't understand much of the wording of the .htaccess file. Just know what it does!! The script I'm writing, maybe I'll pm it to you just so you can see what you have helped me to achieve!!

I believe I now have enough information to get this script completed. :)

Thanks again for all your help. You've been the most helpful with this, and I've asked this on 2 forums!! This one was second. But I haven't had any answer on the other forum!!

Smithster.

Edit.....

Well I seem to have hit another milestone!!!
The part in this script where it echoes out, I generally echo out first as a test to make sure I get the right result. In order to write the output to a file, I have to create a variable to store it in. If I do this....



for($i=0; $i<count($names) || $i<count($passwords);$i++){
//echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
$content = ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
echo $content;
$file = fopen("/home/psmith83/public_html/test/test.htpasswd", "w");

fwrite($file, '' . $content . '');

fclose($file);
}


$content is output on screen in the correct way. But the file that's created does not look right. Even though I'm telling it to output $content on screen, and then write it to a file. Strange in my eyes, but maybe an error on my part! In the file, it's only writing the last username and password. Also, it's putting <br> at the end of it too!!

Anything you can see wrong with this?

Once again, really appreciating your help on this, I just didn't expect to be facing this problem!!

Thanks

Smithster.

Jas
12-16-2007, 12:51 AM
EDIT Sorry, misread the code.

The reason it won't work is because it keeps overwriting the file.
Put the fwrite outside of the loop, and concat the data in the $content var, like so:


for($i=0; $i<count($names) || $i<count($passwords);$i++){
//echo ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
$content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'<br>';
}
echo $content;
$file = fopen("/home/psmith83/public_html/test/test.htpasswd", "w");
fwrite($file, '' . $content . '');
fclose($file);


This way it does it all at once. I asume you know what the concat ('.') does, but incase you don't:

$var = 1;
$var=2;
echo $var;//outputs 2
$var .= 1; //concat 1-- makes value 21
echo $var; //outputs 21

As far as the class, it wan't that great. I am a self taught programer too, as are many on DD as far as I know.

EDIT2: Note: you can also append the info in the file fopen('file','a') (a instead of w) but doing it after is better in this case--or so I think.

smithster
12-20-2007, 03:45 PM
Sorry for the long reply again Jas, had to put this on hold for a few days as work has asked of me all the hours God sends!!! Finally finished for the weekend!! So back to this.....

Have never heard of "concat", looking at your example, I think I get what it means. But it doesn't seem to be helping me!! It hasn't changed the output at all. Output on screen is still perfect, just the text in the created file is wrong.

Here's what it puts in file....


username:password<br>username:password<br>

So that's everything on 1 line. The <br> should not be there at all. This should be indicating a new line needs to be started.

Any more ideas?!?!?

Thanks again, and sorry again for the long reply. I just have been so tired after work to even attempt to look at this until now!!

Smithster.

Master_script_maker
12-20-2007, 11:15 PM
'<br>' is only a newline when it is read by the browser, the browser recougnizes it as html and displays it as such. in a file '<br>' means the accual text "<br>" ('<' with a 'b' then an 'r' and a '>'). try replacing '<br>' with '/n'
sorry for the misspellings

smithster
12-21-2007, 01:27 AM
Thanks Master_script_maker, but unfortunately it does almost the same thing except it does this....



username:password/nusername:password/n

Jas
12-22-2007, 11:12 PM
don't use
/n use
\n
Notice the difference in the slash. This / is a character, this \ is an operator. :) Your OS might want a \r instead, if that doesn't work.

smithster
12-23-2007, 03:13 PM
Here is what I have tried...


$content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'\n';



$content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'/n';



$content .= ''.preg_replace('/[\r\n]/','',$names[$i]).':'.crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode).'\r';


And Here is the output of each one...


user:password\nuser:password\n

user:password/nuser:password/n

user:password\ruser:password\r


Each one in the output has slashes by the way, for some reason the phpcode thing omits them!

thetestingsite
12-23-2007, 03:31 PM
I don't know why, but for some reason you have to use double quotes ( " ) in order for \r\n characters to work right. You may want to try that.



$content .= preg_replace('/[\r\n]/','',$names[$i]).":".crypt(preg_replace('/[\r\n]/','',$passwords[$i]),base64_encode)."\r\n";


Hope this helps.

smithster
12-23-2007, 03:42 PM
Thank you!!! This has been bugging me for a very long time!!! Finally it is now working properly.

Thank you to Jas and to thetestingsite for all your help on this.

Smithster.

Jas
12-23-2007, 09:58 PM
That is a really odd bug. I'll have to keep that in mind myself. Thanks thetestingsite.