Jul 24, 2008

Converting Characters In A Variable To Individual Values In An Array - turning variables into arrays

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Converting Characters In A Variable To Individual Values In An Array - turning variables into arrays

electriic ink
Say I have a variable such as $nav_item and it had to contents Home. IE:

CODE
$nav_item = 'Home';


How would I make so that $nav_item was an array and had the following contents?

CODE
$nav_item = array ('h', 'o', 'm', 'e');


With the case changing (ie H would become h and U would become u)

EDIT: Okay found out that I could change the case with array_change_key_case ($nav_item, CASE_LOWER);

 

 

 


Reply

WindAndWater
Taken from http://us2.php.net/manual/en/function.preg-split.php
CODE
$str = 'string';
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);


You can also just access individual characters in as string by treating it like an array, so "$str[2]" would return "r".

Reply

electriic ink
Thank you WindAndWater smile.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : converting, characters, variable, individual, values, array, turning, variables, arrays

  1. Converting A Blogspot Account Into A .com Domain
    (0)
  2. Vb Variable Help
    help with variable (1)
    I am curently quarying a mysql database, however I am struggling retrieving variables from the
    script I have downloaded from vbmysqldirect. Here is the code: CODE
    '--------------------------------------------------------------------------------------- '
    Module    : mListviewLoader ' DateTime  : 03/07/04 14:06 ' Author    :
    Robert Rowe ' Purpose   : Modified to work with VBMySQLDirect
    '--------------------------------------------------------------------------------------- '
    '    Copyright 2003 Mike Hillyer (ww....
  3. Arrays And List Boxes
    VB6 Codes needed (2)
    Hello Guys, I am working on an application. It is such that there are 2 list boxes or combo boxes.
    One is Labeled Departure and the other is labeled Destination. The boxes contain various states in
    America and each state has its unique feature of distances. The difference of the distances has to
    be reflected on a label. Where I need help is a code to execute the contents of the array into
    values For instance: Option Explicit Private Type Stateinfo statedeparture as integer
    stateDestination as integer TotalDistance as integer End Type Dim StateDistance ....
  4. Converting Audio Files In Vista
    how do you do it? (7)
    Ok, so I have some .wav files that I'd like converted into .mp3. I knew how to do it in XP, but
    I can't find windows audio converter in Vista....does vista even have that, or is it under a new
    name? Also, is it possible to convert video files, like .flv into .avi?....
  5. Array Pointers Can Be Backwards
    (Kind of) (4)
    I just found this out today: When you're using arrays, when you reference a certain index, you
    can switch the pointer and the subscript around. I know I'm not explaining that very good, but
    here's and example: CODE int a[] = {1,2,3,4,5,6,7,8,9,10,11}; int b =1; int
    c[] = {0,-5,11,0,0,5,0,0,0}; cout << b[a][c];    //Same as
    c[a[b]]; See? 'b' is actually just an integer, it's not an array,
    or pointer, or anything. Usually, you would have to put the array first, then an integer. Like....
  6. Unexpected T_variable...
    Help! (3)
    I did construct the database connection file which is called "config.php". But, I got some mistake
    that has to be solved to continue with working. This is the code itself: //Set the database
    values $confg ="alex1985_admin" //Your database username $confg ="" //Your database
    user's password $confg ="localhost" //Your host $confg ="books" //Your database name
    //Create the function to log into the DB function db_login() { global $confg; $link =
    @mysql_connect($confg , $confg , $confg ) or die("Error connecting: " . mysql....
  7. Domain Constants --- A, Mx, Ns & Cname Values
    What should I input for A, MX, NS & CNAME Values at Domain Registr (2)
    Hi, I have registered with Trap17 for a Beta Hosting Acc. Its domain name is zoebelkin.co.cc . So
    what valuse should I put in the Host, Type & Value(Target) fields for my domain's A, MX, NS &
    CNAME Records at my domain registrar co.cc's CPanel. I have two subdomains
    http://forums.zoebelkin.co.cc & http://gallery.zoebelkin.co.cc . My mail Server at Trap17
    is mail.zoebelkin.co.cc . I'm hosted on ' gamma ' Server (
    http://gamma.xisto.com ). IP for the ' gamma ' Server is 64.69.46.210 So what
    exactly should b....
  8. [ruby]lite Multi-dimensional Array
    (0)
    Hey everyone, What I have here is a really simple Multi-Dimensional Array class. This is a Lite
    version with only very basic features. It supports 2- and 3-Dimenional Arrays, and it only really
    has capabilities for storing and accessing data. I am working on a fully featured version of the
    class, but it's going in a game engine I am working on that I'll hopefully be selling
    licenses for, so it would do no good to release all the classes in it. /biggrin.gif"
    style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> This class has relatively
    good p....
  9. Remove A Value From A Php Array Based On Its Value
    (5)
    I have an index array CODE $array[0] = 10; $array[1] = 12; ...
    Its kinda late and I'm falling asleep now but I had a quick look through PHP.net, and could not
    find what I'm after, Maybe I'm too sleepy, sorry, but if anyone knows off the top of their
    head a way to removed members in that array based on its value, i.e. I wanna remove values 12. I
    don't really want to do a loop but if I cant find any existing function to do it, then I may
    have to. Thanks for any help.....
  10. Special Characters In The Web Address
    help nedded for using special characters in the path and then usin the (0)
    hi i am new to htaccess. i was trying to write a rewrite rule in the htaccess for utilizing
    special characters but was unsuccessful...... cud pl anyone help me out working out the same.....
    here's it i a trying to rewrite the following url CODE
    http://www.example.com/*service:forums|passive:true as CODE
    http://www.example.com/index.php?service:forums|passive:true the code i added in
    htaccess was...... CODE Options +FollowSymlinks RewriteEngine on RewriteRule
    ^\*(.+)$ index.php?$1 [nc] ....
  11. Script Help Required: Undefined Variable
    A fault I cannot spot in PHP (3)
    Hi, when running a PHP script I keep getting the error: QUOTE Notice: Undefined variable: bret
    in c:\program files\easyphp1-8\home\poll.php on line 294 Notice: Undefined
    variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294 (And,
    yes, I get it twice). The code related to the variable is as follows: CODE function
    LogString($string,$type)     {         $t_log = "\n";
            $t_log .=
    $this->globaldata->server_vars['REMOTE_ADDR']."....
  12. Counting Variables?
    (4)
    Write a php script that will accept a positive integer, if it is even, divide it by 2 and if it is
    odd, multiply it by 3 and add 1. Repeat the process until the value is 1, printing out each value.
    Finally print out how many of these operations you performed. If the input value is less than 1,
    print error and perform an exit(); For example: Initial value: 9 Next value: 28 Next value: 14
    Next value: 7 Next value: 22 Next value: 11 Next value: 34 Next value: 17 Next value: 52 Next
    value: 26 Next value: 13 Next value: 40 Next value: 20 Next value: 10 Next value: 5 Nex....
  13. Php Sessions And Post Variables Issues
    My script dosent seem to work as intended (1)
    You can test it out for yourself at http://sonesay.trap17.com/application.php I've been
    working on this page locally and it seems to be working fine but when I upload it to my trap17
    account the post variables dont get saved properly. Fill in some fields and submit it, the form
    will come up as a empty field yet when you resubmit it without any modifications and the data you
    entered in orginally will now magically appear, resubmit it again and it will be gone. This is
    really annoying as I have no clue why it would be doing this when it seems to work fine locally.....
  14. Favorite Video Games Characters
    From the old NES to the new Xbox360 and PS3 (1)
    I remember playing the old Zelda games on the NES system and Link was little more then a 8-bit dot
    with big ears and a green hat. It really didnt have much of a story plot to it and the characters
    weren't really in depth, but it was still fun to play. As the gaming world advanced, graphics
    got better and game system held more memory. This gave me a new respect for gaming because Link had
    a personally, life like and believable. Metal gear was also one of my favorites. In the old nes game
    I really didn't care if I die, it was like "ok whatever Im dead" but in the P....
  15. C++ Lesson 2: Variables
    Tutorial for C++ (0)
    As i said on other tutorial. This are tutorials from Gaianlurker on the New Engin3 forum. Alright,
    this tutorial was going to be Variables and Functions, but that would just be massive so I broke it
    down. Let's start with a basic program; CODE #include <iostream.h> //cin and cout
    functions are here int main() { int a, b;    cout<<"Welcome to
    GaianLurker's basic math thingy."<<endl;    cout<<"Please enter a
    number."<<endl;    cin>>a;    cout<<".. and
    another?"<<en....
  16. Converting Textarea Return Characters To <br />
    (8)
    Hi guys, I have set up a form with a textarea. If I have text on multiple lines such as: CODE
    here is some content here is some more content then when I print it out as html it will be
    returned on one line like so: CODE here is some contenthere is some more content When i
    look at the content in the database it looks just like the original way i entered it (contains the
    multiple lines). Is there a function in php so that when i spit it out in html it retains the
    multiple line format? Thanks in advance. ....
  17. Php Variable Basics
    Where would PHP programmers be without the variable? Learn all about t (9)
    CODE <?php $var= "This is a variable"; echo $var; ?> Outcome This is
    a variable Using what we know about the echo function, we can see that we have created a
    variable, and then used the echo command to display it. This is fairly simple, and can have many
    uses, but there is much more too it! CODE <?php $var1 = "This is variable
    one"; $var2 = "This is variable two"; $varall = "$var1. $var2.
    You just combined three variables in one!"; echo $varall; ?> Outcome This is....
  18. Tricks With Php Variables
    (10)
    You probably are thinking at this moment why I am posting some tricks with variables. Well, there
    are many useful things a variable can do for us. For one they can actually be used to create simple
    games. They also can be used to produce a random result in a page. Another great use is shoutboxes.
    Well here are some cool variable effects. Adding Multiple Strings We can use strings to create
    great effects. Example: CODE <?php $var1="Hello person.";
    $var2=str_replace("person","world",$var1); echo $var1."
    &....
  19. A Small Html Problem
    How to display foreign characters correctly when designing a site. (4)
    I was wondering how I could solve a small problem. I was told that some people see accented and
    umlauted letters (such as " é " and " ė ") as question marks (" ? ") on my website. I come across
    the same thing sometimes when looking at websites which use non-English characters. Funnily enough,
    the other day, I looked at a site and the apostrophy ( ' ) was also shown as a question mark.
    That is a very common character usually, I would think. I thought it had something to do with the
    character encoding settings, and let me also mention I use Mozilla Firefox as my brows....
  20. What Is A Fibonachi's Array?
    Deffinition about Fibonachi's array (5)
    Fibonachi's array is a mathematical array noticed in a lot of chemistry, science and biology
    advents. It is an array of numbers which addend of two before numbers give next article of array,
    but this rule doesn't apply for first and secon article 1 and 1. Appearance of array: 1, 1, 2,
    3, 5, 8, 13, 21, 34, 55, 89, 144... Array got name per Italian mathematician Fibonachi.....
  21. Array Problem
    (4)
    I'm having trouble with an assignment for my data structures class.


    I have to simulate a
    card player getting a a pile of 52 cards (a full deck).
    ....
  22. Sonic Style Characters/drawing Requests
    (1)
    Can anybody tell me some websites that have to get some sonic style charries or if anybody is any
    good at drawing their own charcaters like this one for instance... ....
  23. Who's Your All Time Favourite Hidden Characters?
    Street Fighter, Mortal Kombat, X-Men Games. (3)
    You know how you go through certain games and you play at the hardest level or you beat a game
    without ever losing around because you're that darn good. And usually you are rewarded by
    fighting a secret character. These are characters that are above the regular characters you fight
    against. Hidden Characters almost always have that unfair advantage over every single little thing
    that you do. And if you somehow manage to beat this hidden Character he/she might become playable
    using a code or not. Hidden characters --- There's always a catch for you to actually u....
  24. Variable Definition
    (6)
    I am creating a checkbook balancing program that uses multiple forms. The first form will allow the
    user to enter a certain number of deposits, withdrawals, etc. I want to have the ability to have the
    user be able to enter more than what this first screen will provide by allowing them to transfer to
    another form. I would like to store the data entered for each of these transaction types into a
    global variable (to be used throughout the project) array, and produce a total of the dollar amount
    of this transaction type to be used in coming up with an ending balance of the a....
  25. Flv1 Codec Video Converting Help
    any software to convert it to avi? (6)
    My friend just sent me a video file using the FLV1 codec, is there anyway to convert this video file
    into .AVI format besides having to use VLC media player to play it? Thanks in advance....
  26. Transfer Variables To Another Php Script
    (8)
    Hello, I've one registration page where the users fills in their information, is it possible to
    trasnfer the things the fill in on the registration page to another script that does someting and
    returnes something to the first page like true/false and then the registration gives an error
    messange if the other php script returned false? Something like the script "activates" another
    script that does something and returnes the result back to the original script. Best Regards ....
  27. Super Smash Bros Melee
    the best GCN game?+fav characters (35)
    so many people love SSBM. people buy the GCN just for this game! here we shall discuss random
    stuff about it's greatness! my best characters:(ordered) 1.Falco 2.Luigi 3.Peach 4.Roy
    5.Young Link/ Link (same) this game in my opinion is the best fighting game ever. it takes skill
    and a noob cant just walk up and button mash and win against an advanced player like in other
    fighting games. even the cheepest tactics can be countered by a skilled player. according to many
    tiers(best character lists) there are the top characters: 1.Sheik(not zelda) 2. Fox 3. Marth....
  28. Joystick Problem
    Converting Game Port to USB (3)
    This looks like the closest matching forum for my problem; apologies if it's not. I have an old
    MS SideWinder Pro Plus joystick that I've had forever, mainly to play X-Wing vs. TIE Fighter. I
    recently got the urge to play it again, but when I dragged the trusty SideWinder out of the storage
    box, I discovered my Abit NF7-S2 mobo doesn't have a game port. It does have onboard sound, so I
    don't have the usual sound card game port either. I bought a Belkin DB-15 joystick game
    port-to-USB adapter off the net. It's supposedly specifically for SideWinders,....
  29. Turning An Image Into A Cartoon Style - Photoshop
    Tutorial on cartooning images. (30)
    This tut will show you how to make a photo look cartoonish in three easy steps... 1)Open your
    image in photoshop, doesnt really mater what size or shape anything really a landscape, city, or a
    person. I am using a picture of a football player in this example 2)Go up to
    Filter>Blur>Gaussian Blur and set the radius at 3.0 or higher depending on the effect your looking
    for. 3)Last go Edit>Fade Gaussian Blur. A window will pop up... set the mode to darken for tha
    cartoonish effect or to any other mode for plenty of other effects. Lower the opacity if you
    don't....
  30. Converting Video Files From One Format To Another
    help plz :) (6)
    hey i have learnt this nice way to open mov files in imageready and insert them in sigs,graphics and
    other stuff its really cool,this only works with .mov files and i really need to know if sumone here
    can do that,i need to change a wmv file into a .mov file so i cant add the movie to a sig,i have
    tried many video format conversion programs but they dont accept the mov format,the mov format is a
    quicktime video format,so anyone here know how to change a video file into a quicktime mov video
    format? thnx in advance....

    1. Looking for converting, characters, variable, individual, values, array, turning, variables, arrays

Searching Video's for converting, characters, variable, individual, values, array, turning, variables, arrays
Similar
Converting A
Blogspot
Account Into
A .com
Domain
Vb Variable
Help - help
with
variable
Arrays And
List Boxes -
VB6 Codes
needed
Converting
Audio Files
In Vista -
how do you
do it?
Array
Pointers Can
Be Backwards
- (Kind of)
Unexpected
T_variable..
. -
Help!
Domain
Constants
--- A, Mx,
Ns &
Cname Values
- What
should I
input for A,
MX, NS &
CNAME Values
at Domain
Registr
[ruby]lite
Multi-dimens
ional Array
Remove A
Value From A
Php Array
Based On Its
Value
Special
Characters
In The Web
Address -
help nedded
for using
special
characters
in the path
and then
usin the
Script Help
Required:
Undefined
Variable - A
fault I
cannot spot
in PHP
Counting
Variables?
Php Sessions
And Post
Variables
Issues - My
script
dosent seem
to work as
intended
Favorite
Video Games
Characters -
From the old
NES to the
new Xbox360
and PS3
C++ Lesson
2: Variables
- Tutorial
for C++
Converting
Textarea
Return
Characters
To <br
/>
Php Variable
Basics -
Where would
PHP
programmers
be without
the
variable?
Learn all
about t
Tricks With
Php
Variables
A Small Html
Problem -
How to
display
foreign
characters
correctly
when
designing a
site.
What Is A
Fibonachi
9;s Array? -
Deffinition
about
Fibonachi
9;s array
Array
Problem
Sonic Style
Characters/d
rawing
Requests
Who's
Your All
Time
Favourite
Hidden
Characters?
- Street
Fighter,
Mortal
Kombat,
X-Men Games.
Variable
Definition
Flv1 Codec
Video
Converting
Help - any
software to
convert it
to avi?
Transfer
Variables To
Another Php
Script
Super Smash
Bros Melee -
the best GCN
game?+fav
characters
Joystick
Problem -
Converting
Game Port to
USB
Turning An
Image Into A
Cartoon
Style -
Photoshop -
Tutorial on
cartooning
images.
Converting
Video Files
From One
Format To
Another -
help plz :)
advertisement



Converting Characters In A Variable To Individual Values In An Array - turning variables into arrays



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE