convert each character in string to array

01-30-06, 02:40 PM
|
|
Newbie Coder
|
|
Join Date: Dec 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
convert each character in string to array
Anyone know the best way to convert all the characters in a string into an array
for example
|

01-30-06, 03:25 PM
|
 |
Community Leader
|
|
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
|
|
|
|

01-30-06, 03:30 PM
|
|
Newbie Coder
|
|
Join Date: May 2004
Location: Albania
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Note that you can access the string characters also with this syntax, using [] instead of {}, anyway if you want to have array functionality you can do it in that way.
|

01-30-06, 03:43 PM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
In PHP a string is actually an array, so $foo ="hotscripts", you could access the "h" with $foo[0], the "o" with $foo[1], and so on.
|

01-30-06, 06:36 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
Quote:
|
Originally Posted by End User
In PHP a string is actually an array, so $foo ="hotscripts", you could access the "h" with $foo[0], the "o" with $foo[1], and so on.
|
I think that's done with curly braces as opposed to square brackets. So in your example: $foo{1} == "o".
Quoted from http://www.php.net/substr:
Last edited by Keith; 01-30-06 at 06:42 PM.
|

01-30-06, 09:05 PM
|
 |
Community VIP
|
|
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Both [] and {} work. However, if you include the {} form in a quoted string, the results are not as expected -
Results in this output -
The 1st char of the string is: a
The 1st char of the string is: abcdef{0}
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Last edited by mab; 01-30-06 at 09:09 PM.
|

01-30-06, 09:41 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
|
|

01-30-06, 09:53 PM
|
|
Wannabe Coder
|
|
Join Date: Nov 2003
Posts: 165
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
|
Originally Posted by mab
Both [] and {} work. However, if you include the {} form in a quoted string, the results are not as expected -
Results in this output -
The 1st char of the string is: a
The 1st char of the string is: abcdef{0}
|
Or if you always use {} for strings, etc, then you don't have the problem:
Last edited by Patiek; 01-30-06 at 09:59 PM.
|

06-20-09, 12:16 PM
|
|
New Member
|
|
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
use this
$data is an array 
|

06-21-09, 12:36 AM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
A three and a half year old topic dude. Really?
__________________
The toxic ZCE
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|