Jump to content


Photo

explode() help


  • Please log in to reply
3 replies to this topic

#1 ssjskipp

ssjskipp
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 14 May 2006 - 04:35 AM

Okay, is there a way to explode, say:
$a = "test";
into an array of:
$array = ["t", "e", "s", "t"]

EDIT:

Nevermind, I got it:
"$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);"

#2 KrisNz

KrisNz
  • Members
  • PipPipPip
  • Advanced Member
  • 271 posts
  • LocationAuckland, New Zealand

Posted 14 May 2006 - 04:43 AM

str_split would be a bit faster.

#3 ssjskipp

ssjskipp
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 14 May 2006 - 04:56 AM

[!--quoteo(post=373653:date=May 14 2006, 12:43 AM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ May 14 2006, 12:43 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
str_split would be a bit faster.
[/quote]
it's plenty fast for what I need.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 14 May 2006 - 09:57 AM

You can treat a string as an array of characters

$a = 'test';

for ($i=0; $i < 4; $i++)
{
         echo $a{$i} . '<br>';
}

-->
t
e
s
t

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users