Re: [PHP] Re: help with end of line charater

2009-01-31 Thread tedd

At 11:58 AM -0600 1/30/09, Adam Williams wrote:

yeah just a second ago a big lightbulb went off in my head



Try a bigger light-bulb and store the email addresses in a database. 
Then you can use them as you want regardless if the user hit return 
or not.


Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Re: help with end of line charater

2009-01-31 Thread Jim Lucas
tedd wrote:
 At 11:58 AM -0600 1/30/09, Adam Williams wrote:
 yeah just a second ago a big lightbulb went off in my head
 
 
 Try a bigger light-bulb and store the email addresses in a database.
 Then you can use them as you want regardless if the user hit return or not.
 
 Cheers,
 
 tedd
 
 

I don't think majordomo can talk to a DB can it?

Or maybe he doesn't want to configure it to do so even if it can.

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] Re: help with end of line charater

2009-01-30 Thread Shawn McKenzie
Adam Williams wrote:
 I have staff inputting email addresses into a textarea named $list on
 a form and when they click submit, my php script sorts the email
 addresses and writes to disk.  The problem is, lets say they enter the
 email addresses
 
 b...@mdah.state.ms.usstaff hits enter
 ama...@mdah.state.ms.usstaff hits enter
 sa...@mdah.state.ms.usstaff hits enter
 j...@mdah.state.ms.usstaff hits enter
 ci...@mdah.state.ms.usstaff does not hit enter and clicks on submit
 button
 
 then views the sortes email addresses, it displays as:
 
 ama...@mdah.state.ms.us
 b...@mdah.state.ms.us
 ci...@mdah.state.ms.usjoe@mdah.state.ms.us
 sa...@mdah.state.ms.us
 
 because the staff didn't hit enter on the last line.  Is there a way to
 read each line of input and add a carriage return if needed?  I tried
 the code below but it did not work, nothing happened, and i don't know
 to examine each line to see if it ends in \r\n either.
 
 $list2 = explode(\r\n, $list);
 
 foreach ($list2 as $key = $var)
{
 
$var = $var.\r\n;
 
}
 
 $list = implode(\r\n, $list2);
 
 
This may be best handled in your sorting code.  What does it look like?

-- 
Thanks!
-Shawn
http://www.spidean.com

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



[PHP] Re: help with end of line charater

2009-01-30 Thread Shawn McKenzie
Shawn McKenzie wrote:
 Adam Williams wrote:
 I have staff inputting email addresses into a textarea named $list on
 a form and when they click submit, my php script sorts the email
 addresses and writes to disk.  The problem is, lets say they enter the
 email addresses

 b...@mdah.state.ms.usstaff hits enter
 ama...@mdah.state.ms.usstaff hits enter
 sa...@mdah.state.ms.usstaff hits enter
 j...@mdah.state.ms.usstaff hits enter
 ci...@mdah.state.ms.usstaff does not hit enter and clicks on submit
 button

 then views the sortes email addresses, it displays as:

 ama...@mdah.state.ms.us
 b...@mdah.state.ms.us
 ci...@mdah.state.ms.usjoe@mdah.state.ms.us
 sa...@mdah.state.ms.us

 because the staff didn't hit enter on the last line.  Is there a way to
 read each line of input and add a carriage return if needed?  I tried
 the code below but it did not work, nothing happened, and i don't know
 to examine each line to see if it ends in \r\n either.

 $list2 = explode(\r\n, $list);

 foreach ($list2 as $key = $var)
{

$var = $var.\r\n;

}

 $list = implode(\r\n, $list2);


 This may be best handled in your sorting code.  What does it look like?
 

Before you sort: $list .= \r\n;

-- 
Thanks!
-Shawn
http://www.spidean.com

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



Re: [PHP] Re: help with end of line charater

2009-01-30 Thread Adam Williams

Shawn McKenzie wrote:

This may be best handled in your sorting code.  What does it look like?
  


yeah just a second ago a big lightbulb went off in my head and i fixed 
my code to add a \r\n on saving, and strip it on viewing.  I sort on 
viewing, not sort on saving.  The viewing code looks like:


$biglist = ;

$filename = /usr/local/majordomo/lists/.$edit;

$fp = fopen($filename, r) or die (Couldn't open $filename);
if ($fp)
   {
   while (!feof($fp))
   {
   $thedata = fgets($fp);
   $buildingvar[] = $thedata;
   }
   sort($buildingvar);
   foreach ($buildingvar as $key = $val)
   {
if ($val != \r\n)  //gets rid of 
empty whitespace lines

   {
   $biglist .= $val;
   }

   }

   }

//$biglist gets echo'd into a textarea box below.

but now right before it is saved, i'll add a new line

$list .=\r\n;

$fp = fopen($filename, w) or die (Couldn't open $filename);
if ($fp)
   {
   fwrite($fp, $list);
   echo 
   headtitleSaving Page/title
   link rel=stylesheet href=/maillist.css type=\text/css\
   /head
   Your mailing list has been updated.;
   }

fclose($fp);

so that upon viewing, if they didn't press enter, a \r\n will be added, 
and even if they did add press enter on the last line, it'll be stripped 
out upon viewing the list of email addresses.




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



Re: [PHP] Re: help with end of line charater

2009-01-30 Thread Konstantin S. Kurilov

Hello Adam!

$list2 = explode(\n, $list); // \n not \r\n
$list = implode(\r\n, $list2);

foreach ... - not need

with the best regards

 - Konstantin Kurilov

Shawn McKenzie wrote:


Adam Williams wrote:


I have staff inputting email addresses into a textarea named $list on
a form and when they click submit, my php script sorts the email
addresses and writes to disk.  The problem is, lets say they enter the
email addresses

b...@mdah.state.ms.usstaff hits enter
ama...@mdah.state.ms.usstaff hits enter
sa...@mdah.state.ms.usstaff hits enter
j...@mdah.state.ms.usstaff hits enter
ci...@mdah.state.ms.usstaff does not hit enter and clicks on submit
button

then views the sortes email addresses, it displays as:

ama...@mdah.state.ms.us
b...@mdah.state.ms.us
ci...@mdah.state.ms.usjoe@mdah.state.ms.us
sa...@mdah.state.ms.us

because the staff didn't hit enter on the last line.  Is there a way to
read each line of input and add a carriage return if needed?  I tried
the code below but it did not work, nothing happened, and i don't know
to examine each line to see if it ends in \r\n either.

$list2 = explode(\r\n, $list);

foreach ($list2 as $key = $var)
  {

  $var = $var.\r\n;

  }

$list = implode(\r\n, $list2);




This may be best handled in your sorting code.  What does it look like?



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



Re: [PHP] Re: help with end of line charater

2009-01-30 Thread Jim Lucas
Adam Williams wrote:
 Shawn McKenzie wrote:
 This may be best handled in your sorting code.  What does it look like?
   
 
 yeah just a second ago a big lightbulb went off in my head and i fixed
 my code to add a \r\n on saving, and strip it on viewing.  I sort on
 viewing, not sort on saving.  The viewing code looks like:
 
 $biglist = ;
 
 $filename = /usr/local/majordomo/lists/.$edit;
 
 $fp = fopen($filename, r) or die (Couldn't open $filename);
 if ($fp)
{
while (!feof($fp))
{
$thedata = fgets($fp);
$buildingvar[] = $thedata;
}
sort($buildingvar);
foreach ($buildingvar as $key = $val)
{
 if ($val != \r\n)  //gets rid of empty
 whitespace lines
{
$biglist .= $val;
}
 
}
 
}
 
 //$biglist gets echo'd into a textarea box below.
 
 but now right before it is saved, i'll add a new line
 
 $list .=\r\n;
 
 $fp = fopen($filename, w) or die (Couldn't open $filename);
 if ($fp)
{
fwrite($fp, $list);
echo 
headtitleSaving Page/title
link rel=stylesheet href=/maillist.css type=\text/css\
/head
Your mailing list has been updated.;
}
 
 fclose($fp);
 
 so that upon viewing, if they didn't press enter, a \r\n will be added,
 and even if they did add press enter on the last line, it'll be stripped
 out upon viewing the list of email addresses.
 
 
 

Taking your code, reworking it a little, this is what I came up with.

?php

# Define  collect variables
$biglist = ;

# Input list from form in browser
$list = $_GET['list'];

# Define your source file
$filename = /usr/local/majordomo/lists/.$edit;

# Check output/input file(s)
!is_file( $filename )   or die(File '{$filename}' does not exist.);
!is_readable( $filename )   or die(I cannot read file '{$filename}'.);
!is_writeable( $filename )  or die(I cannot write to file '{$filename}'.);

# Read file
$file_list = file( $filename );

# Clean up input from file
$file_list = array_map( 'trim', $file_list );

# Clean up input from form in browser
$list = array_map( 'trim', $list );

# Merge the two list together
$merged_list = array_merge( $list, $file_list );

# Sort stuff
sort( $merged_list );

# store the data back into the source file.
if ( file_put_contents( $filename, join(PHP_EOL, $merged_list) ) ) {
$msg = 'Your mailing list has been updated.';
} else {
$msg = 'Your mailing list could not be saved.';
}

# Display message to user
echo headtitleSaving Page/titlelink rel=stylesheet href=/maillist.css 
type=\text/css\/headbody{$msg}/body;

?

Hope this helps

-- 
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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