[PHP] need help w/ Split()

2001-03-08 Thread Scott Walter

I am attempting to take a line of text (a list) that has been entered into 
a form and split it into the appropriate parts, placing them into an 
array.  I am splitting the input on commas, semi-colons, and spaces.

Problem 1:  Is with "white space".  If the input has spaces after a comma, 
it splits on the comma, but enters each "space" as a separate element of 
the array.

Problem 2: Is with "white space" also.  If the input has just spaces 
between the appropriate parts, then it will split on the first "space", but 
enter the rest of the "spaces" as separate elements of the array.

Here my code:
$course_list = preg_split("/[\,\;\s*]/", $input_list);
for ($i=0; $icount($course_list); $i++) {
echo("Item $i: $course_list[$i]br\n");
}

Which on input "0101, 0102,  0103" produces [0101][ ][0102][ ][ ][ ][0103]

Any help would be appreciated!!


-- 
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]




[PHP] Arrays -- How do I insert a pair of data into an array

2001-02-22 Thread Scott Walter

I am attempting to insert a set of data (actually a pair) into an array, 
without much success.  I would like to insert the data set ("course 
number", "course title") into a numerically indexed array so that when I 
want to output the array I can reference it like so:

echo("$array[$i]["course_num"] $array[$i]["course_title"]");

// where $i is just the index value that increments

I tried building the array like so (where $tuple[] is a valid result 
set from pg_fetch_row():

$array[] = array("course_num" = $tuple[crn],
"course_title" = $tuple[course_name]);

But all I gets outputted is:

Array["course_num"] Array["course_title"]

Any help with this would be greatly appreciated.  Thanks.


-- 
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]