SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Using trim().
Hybrid View
-
Jun 18, 2001, 20:57 #1
- Join Date
- May 2001
- Location
- San Diego, CA
- Posts
- 1,701
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using trim().
I have a form which allows the user to select different categories. Each category has a specific ID number, so a typical response would be:
"10, 7, 15, 46, 32"
and this is stored in the variable $categories.
So I obviously want to split this by the commas, I could use explode() or split() but for this example I'll use explode():
$categories = explode(",", $categories);
Now I want to get rid of the white spaces, so I'll use trim(). But, my question is, can I pass the array $categories into trim() and expect to have the white spaces stripped from each element. Or, will I have to do a while loop, extracting the white space individually from each element.
$c = 0;
while($categories[$c])
{
$categories[$c] = trim($categories[$c]);
$c++;
}Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
Get your website started for less than $20! Click Here
-
Jun 18, 2001, 21:43 #2
- Join Date
- Jun 2001
- Location
- Florida
- Posts
- 99
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I believe you'll have to use the while loop. The thing to do is try it.
-
Jun 18, 2001, 21:51 #3
- Join Date
- May 2001
- Location
- San Diego, CA
- Posts
- 1,701
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It worked (the while loop)... thanks!
Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
Get your website started for less than $20! Click Here
-
Jun 19, 2001, 00:14 #4
- Join Date
- Dec 2000
- Location
- The flat edge of the world
- Posts
- 838
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can's you go:
$categories = explode(", ", $categories);
So the explod() gets rid of the whitespace as well?
-
Jun 19, 2001, 09:52 #5
- Join Date
- May 2001
- Location
- San Diego, CA
- Posts
- 1,701
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That would work fine as long as the user added a space after every comma. I thought about the setup I was running, it's much too complicated for the user to use. I'm going to change it so that an array of checkboxes is displayed, then the user will be able to check each category the image should belong to instead of remembering each Category ID.
Ryan Kuhle - A Proud Advisor - Got Questions? Just Ask!
Get your website started for less than $20! Click Here
Bookmarks