LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-18-2006, 02:52 PM   #1
joelhop
Member
 
Registered: Mar 2004
Location: Pennsylvania::USA
Distribution: Fedora Core 6
Posts: 100

Rep: Reputation: 15
Question Php String to Array


I want to build an array from a single word using PHP:


If the word is: linux


I want the array to be:
Array
(
[0] => l
[1] => i
[2] => n
[3] => u
[4] => x

)

Is there a simple way to do this in php?
 
Old 12-18-2006, 03:30 PM   #2
int0x80
Member
 
Registered: Sep 2002
Location: Cincinnati
Distribution: Debian GNU/Linux
Posts: 310

Rep: Reputation: 31
PHP Code:
<?php

$os 
"GNU/Linux";
$arrOS str_split($os);
print_r($arrOS);

/**
 * Output:

Array
(
    [0] => G
    [1] => N
    [2] => U
    [3] => /
    [4] => L
    [5] => i
    [6] => n
    [7] => u
    [8] => x
)

*/
?>
 
Old 12-18-2006, 03:39 PM   #3
joelhop
Member
 
Registered: Mar 2004
Location: Pennsylvania::USA
Distribution: Fedora Core 6
Posts: 100

Original Poster
Rep: Reputation: 15
Thank you! That is exactly what I needed. str_split()
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# convert char array to string exodist Programming 3 09-16-2008 08:06 AM
Convert C++ String Vector to char array anamericanjoe Programming 1 12-12-2006 09:29 PM
String Array definiation problem nelnel Programming 1 09-16-2005 04:56 AM
Perl string replacement within an array? Seventh Programming 1 09-07-2004 02:50 PM
java test if string in string array is null. exodist Programming 3 02-21-2004 01:39 PM


All times are GMT -5. The time now is 08:41 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration