Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting Strings 1

Status
Not open for further replies.

VisBasDude

Programmer
Nov 10, 2002
19
GB
Hi yeah, i have a string for example "JAMES" and i want to split it into the separate letters e.g. "J","A","M","E","S" and load this into an array. I was using the explode statement like this $Name = explode("",$Data) but this doesnt seem to work. Any ideas how i could do this in other ways?? James
 
In PHP, all strings are arrays by default. For instance, if [tt]$string = "test";[/tt], then [tt]$string[0][/tt] would be equal to "t". //Daniel
 
Isn't that sposed to be done with {} instead Dan or is that just an option? ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
This can also be done with the {}, it was a post made by either Rycamor or Anikin I think, a while ago. just tested it for something to do and it does in fact work. I'm sure the poster said it was a C thing.

Whatever, more options :)

Heres a question tho, how would you get say 3 characters together without typing too much:

eg $string="abcdef";

how would I get "bcd" can it be done something like $string[1..3] ?

Go on , a star for the person that doesn't make me type $string[1]$string[2]$string[3] all the time :) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The new Zend engine V2, will use {} to make a distinction between strings and arrays --BB
 
and waking up before posting will lessen sh*** posts.

substr($string,x,y);

give myself a *, well pointed out BB101, until we all have that {} will be happy. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Since strings are internally arrays of characters, it seems to me like the array subscripts are more natural. //Daniel
 
I always used {} purely because that was what I saw in the documentation. Didn't know you could use [] as well. Don't suppose it really matters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top