Re: [PHP] php javascript

2001-10-03 Thread Matthew Armsby

Leave the input name as email.  If you really want to call it email[], 
you should be able to reference this in JavaScript as the object 
document.myform[email[]]

If you leave it as email, you can then convert the email variable into an 
array using explode() or split() as so:
?php
// on the recieving page, of course
$emailArray = explode (,, $email);
// Alternatively, a bit of RE exploding...
$emailArray = split (,, $email);
?

Matt

 Hey all!
 
 I'm including some javascript that enables a button in a form  
 input type=button name=CheckAll value=Check All
 onClick=checkAll(document.myform.email)to check all
 the check boxes at once. (I have an array of check boxes from a mysql
 db)
 
 I use:
 
 SCRIPT LANGUAGE=JavaScript
 !-- Begin
 function checkAll(field)
 {
 for (i = 0; i  field.length; i++)
  field[i].checked = true ;
 }
 
 function uncheckAll(field)
 {
 for (i = 0; i  field.length; i++)
  field[i].checked = false ;
 }
 //  End --
 /script
 
 So... In order to use this script my button has to have
 onClick=checkAll(document.myform.email) and my check boxes have to
 have name=email but i need to name them name=email[] in order to
 pass the variables as an array in php. ive tried using
 onClick=checkAll(document.myform.email[]) but that just gives me an
 error for obvious reasons im sure. I don't know jack about javascript,
 so if you know of a better way to make a button that selects all check
 boxes or another way to code how the check boxes values are passed to
 the next page, I would be so greatful.
 
 Thanks!
 Nate



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] php javascript

2001-10-03 Thread Matthew Armsby

 document.myform[email[]] seems to give me a syntax error.

Check if your already using  you'll need to use single quotes as so:
input type=button name=CheckAll value=Check All
onClick=checkAll(document.myform['email[]'])
(tested on IE 5.5 and NS 4.08, works)

 If you leave it as email, you can then convert the email variable into an
array using explode() or split() as so:

  On the recieving page I have echo($array = implode (,, $email));
which echos the array of text box values just fine. but only if the input
name=email[] not name=email, and email[] doesnt work since my javascript
uses email, not email[]

If you want to continue using email[], the above advise should be okay, and
no need to read on.
If you want to use email, instead of echo(implode(,, $email)), just
echo($email), then you can use explode() when you want the array.
?php
// When using $email, not $email[]
// The comma seperated string:
echo($email);
// The array:
$ar_email = explode(, $email);
// The array glued for viewing:
echo(implode (,, $ar_email));
?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Parsing a CSV file

2001-10-03 Thread Matthew Armsby

Example

?php
exampleLine = R001,23,\2,5\;

preg_match_all (/(\[^\]+\|[^,]+)/, exampleLine, $matches);

for ($i=0; $i count($matches[0]); $i++) {
echo matched: .$matches[0][$i].br;
}

?

Please note, empty elements will not be handled

btw Any Australian employers want a programmer for awhile?

- Original Message -
From: Sharat Hegde [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, October 03, 2001 9:55 PM
Subject: [PHP] Parsing a CSV file


 Hello,

 I am trying to parse a CSV (comma separated file) file to get the separate
 elements. The format of each line of the file is as follows:

 R001,23,2,5

 Note that the 3rd field 2,5 is enclosed within quotes as it has commas
 within the field itself. This is a standard file created when an Excel
file
 is saved as a CSV file. What I need after parsing this is an array with
the
 elements being:
 Element 0 - R001
 Element 1 - 23
 Element 2 - 2,5

 Standard split command gives 4 elements instead of 3.

 I know I can do this by some brute programming, but is there an elegant
way
 out. Note that I am not using PHP 4.0 and hence PHP4 specific features are
 not available to me as yet!

 Regards,
 Sharat



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]