SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: convert string to array
-
Jan 6, 2009, 04:38 #1
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
convert string to array
Hi,
I have a string like this
$string = "computer mousecomputer keyboardgame padmonitorphonecardogcat"
when read correctly they are:
computer mouse
computer keyboard
game pad
monitor
phone
car
dog
cat
The problem is I don't know what to put in explode() first parameter to get the array with those values.
-
Jan 6, 2009, 04:44 #2
you need something to separate the items.
-
Jan 6, 2009, 04:44 #3
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
You cannot do it with that string I'm afraid, there is no programmatic approach given the information supplied.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Jan 6, 2009, 05:01 #4
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think i should've started from the beginning
Code PHP:while ($subcat_rows1 = mysql_fetch_assoc($subcat_result1)) { $groups = $subcat_rows1['meaning']; }
echo $groups
output will be the string I've given.
Is there any way we can format the string before converting to array ?
-
Jan 6, 2009, 05:05 #5
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
If 'meaning' contains each individual entry ('game pad' for example) you could just alter your loop slightly to produce an array.
PHP Code:$groups = $subcat_rows1['meaning'];
PHP Code:$groups[] = $subcat_rows1['meaning'];
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Jan 6, 2009, 07:03 #6
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Many thanks.
Bookmarks