Re: [PHP] String to Array or Hash Table

2003-10-19 Thread Duncan Hill
sun zheng said:
>>tx for the reply.. ya, it is what i am looking for.. however, your solution
>>is not the right one.. please help me to adjust it a lot..
>>
>>let us come back to the initial string ..
>>"approved=yes&error=&authnumber=025968&transactionnumber=313869";
>
>>I definately want to get something like
>>$value_array['approved'] is "yes"
>>$value_array['error'] is ""
>>$value_array['authnumber'] is "025968"
>>$value_array['transactionnumber'] is "313869"

> If it's just a string, something like:
> $data_array = split('&', $string);
> foreach ($data_array as $key) {
> list($mykey, $value) = split('=', $key);
> $value_array[$mykey] = $value;
> }
> ###
>
> thank you.. but .. it is still different as what i expect... :(
>
> ya, it is only a string, not a link which could be captured by $_get[].. :(
> "approved=yes&error=&authnumber=025968&transactionnumber=313869"
>
> let's just take a look at your final array "$value_array[$mykey] = $value;"
>
> key <-> content will be
> 0 -  approved
> 1 - yes
> 2 - error
> 3 - null
> 4 - authnumber
> 5 - 025968
> 6 - transactionnumber
> 7 - 313869

I stated that the code was untested.  If I didn't, oops.  Massaging it into a
format you can use is left as an excercise for the reader - it is not my aim
to provide fully working, tested code when I have better ways to spend my time
:)

print_r($var) is your friend, apply liberally at critical stages to see if the
data is in the format you want.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] String to Array or Hash Table

2003-10-19 Thread sun zheng
tx for the reply.. ya, it is what i am looking for.. however, your solution
is not the right one.. please help me to adjust it a lot..
let us come back to the initial string ..
"approved=yes&error=&authnumber=025968&transactionnumber=313869";

I definately want to get something like
$value_array['approved'] is "yes"
$value_array['error'] is ""
$value_array['authnumber'] is "025968"
$value_array['transactionnumber'] is "313869"
If I'm wrong, blame this on coming into the thread at this stage, not the
beginning.
That string look suspiciously like a GET request.

$myvars = array('approved', 'error', 'authnumber', 'transactionnumber');
foreach ($myvars as $key) {
$value_array[$key] = $_GET[$key];
}
If it's just a string, something like:
$data_array = split('&', $string);
foreach ($data_array as $key) {
list($mykey, $value) = split('=', $key);
$value_array[$mykey] = $value;
}
###
thank you.. but .. it is still different as what i expect... :(

ya, it is only a string, not a link which could be captured by $_get[].. :(
"approved=yes&error=&authnumber=025968&transactionnumber=313869"
let's just take a look at your final array "$value_array[$mykey] = $value;"

key <-> content will be
0 -  approved
1 - yes
2 - error
3 - null
4 - authnumber
5 - 025968
6 - transactionnumber
7 - 313869
I want to get something like hashtable..
key <-> content
approved <-> yes
error <-> null
authnumber <-> 025968
transactionnumber <-> 313869
is it possible ? otherwise i have to reserve my old way listed in the first 
thread, using four "if" which is ugly.. :((

with best wishes

Zheng Sun

_
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*. 
http://join.msn.com/?page=features/virus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] String to Array or Hash Table

2003-10-19 Thread Duncan
sun zheng said:
> tx for the reply.. ya, it is what i am looking for.. however, your solution
> is not the right one.. please help me to adjust it a lot..
>
> let us come back to the initial string ..
> "approved=yes&error=&authnumber=025968&transactionnumber=313869";

> I definately want to get something like
> $value_array['approved'] is "yes"
> $value_array['error'] is ""
> $value_array['authnumber'] is "025968"
> $value_array['transactionnumber'] is "313869"

If I'm wrong, blame this on coming into the thread at this stage, not the
beginning.

That string look suspiciously like a GET request.

$myvars = array('approved', 'error', 'authnumber', 'transactionnumber');
foreach ($myvars as $key) {
 $value_array[$key] = $_GET[$key];
}

If it's just a string, something like:
$data_array = split('&', $string);
foreach ($data_array as $key) {
 list($mykey, $value) = split('=', $key);
 $value_array[$mykey] = $value;
}

More than one way to skin a cat, and my foreach loops are probably wrong. 
Simple application of the manual really, in the end.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] String to Array or Hash Table

2003-10-19 Thread sun zheng
tx for the reply.. ya, it is what i am looking for.. however, your solution 
is not the right one.. please help me to adjust it a lot..

let us come back to the initial string .. 
"approved=yes&error=&authnumber=025968&transactionnumber=313869";

after the statement "for (@reset($value_array); 
list($key1,$value1)[EMAIL PROTECTED]($value_array);)",
currently in the array $value_array, it contains such key<->content
key1=0, $value1="approved=yes"
key1=1, $value1="error="
key1=2, $value1="authnumber=025968"
key1=3, $value1="transactionnumber=313869"

therefore current $approved = $value_array['approved'] ; is empry.. i cannot 
get "yes" ..

I definately want to get something like
$value_array['approved'] is "yes"
$value_array['error'] is ""
$value_array['authnumber'] is "025968"
$value_array['transactionnumber'] is "313869"
please think about it once more..

thanks again..



%for (@reset($value_array); list($key1,$value1)[EMAIL PROTECTED]($value_array);)
%{
%  $first = $value1;
%  list($key1,$value1)[EMAIL PROTECTED]($value_array);
%  $second = $value1;
I don't think you need to do this, though, because ...
%
%  if($first == "approved")
%  {
%$approved = $second;
%  }
[snip]
... I don't think you need to go through all of these if() tests.
You have each key and value in your value_array; you should be able
to just say
 $approved = $value_array['approved'] ;

and so on.

This is untested and I am in a hurry, but I hope it puts you on the right
track.


with best wishes

Zheng Sun

_
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] String to Array or Hash Table

2003-10-19 Thread David T-G
Zheng --

...and then sun zheng said...
% 
% Hi, all,

Hi!


% 
...
% I explode it first by "&".
%  $execoutput = 
% "approved=yes&error=&authnumber=025968&transactionnumber=313869";
%  $execoutput_array = explode("&", $execoutput);

I don't see any problem with this.


% 
% I secondly explode every parameter=value string by "="..
% 
%  for (@reset($execoutput_array); 
% list($key,$value)[EMAIL PROTECTED]($execoutput_array);)
%  {
%#output the result for debugging
%$value_array = explode("=", $value);

I don't see a particular problem with this, either, though someone might
be able to do it more efficiently.


%for (@reset($value_array); list($key1,$value1)[EMAIL PROTECTED]($value_array);)
%{
%  $first = $value1;
%  list($key1,$value1)[EMAIL PROTECTED]($value_array);
%  $second = $value1;

I don't think you need to do this, though, because ...
% 
%  if($first == "approved")
%  {
%$approved = $second;
%  }
[snip]

... I don't think you need to go through all of these if() tests.
You have each key and value in your value_array; you should be able
to just say

  $approved = $value_array['approved'] ;

and so on.

This is untested and I am in a hurry, but I hope it puts you on the right
track.


HTH & HAND

:-D
-- 
David T-G  * There is too much animal courage in 
(play) [EMAIL PROTECTED] * society and not sufficient moral courage.
(work) [EMAIL PROTECTED]  -- Mary Baker Eddy, "Science and Health"
http://justpickone.org/davidtg/  Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



pgp0.pgp
Description: PGP signature


Re: [PHP] string to array

2003-02-12 Thread Steve Werby
"Kevin Waterson" <[EMAIL PROTECTED]> wrote:
> What is the best method to convert a string to an array
>
> I need to able to loop through each letter of the string
> not just use $string[47]

You can find out how long it is using strlen(), then loop through it using
your favorite looping construct.  You could also easily convert it to an
array at that point, but unless you need each character as an array element
for a later operation it doesn't seem very efficient.  I don't think
explode() will let you use a separator of '', but you might look at that as
well.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2003-02-12 Thread Leif K-Brooks
There's no built-in function, but try this (copied from manual):

$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);


Kevin Waterson wrote:

>What is the best method to convert a string to an array
>
>I need to able to loop through each letter of the string
>not just use $string[47]
>
>Is there a definitive method to do this?
>
>Kevin
>
>
>

--
The above message is encrypted with double rot13 encoding.  Any 
unauthorized attempt to decrypt it will be prosecuted to the full extent 
of the law.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] string to array

2002-11-08 Thread Maxim Maletsky
Guys, not to confuse you, but I think there is a more elegant way doing
it that. I had the same issue once long ago (2-3 years ago?) and had put
it up on the mailing lists too.

Gotta remember what it was and for what project then find the code in my
libraries. I really think i accomplished it without preg_split()...


--
Maxim Maletsky
[EMAIL PROTECTED]



"@ Edwin" <[EMAIL PROTECTED]> wrote... :

> Hello,
> 
> 
> "Maxim Maletsky" <[EMAIL PROTECTED]> wrote:
> 
> 
> [snip]
> > As of actually converting it you could do that very loop and have an:
> > $atr_arr[] = $str[$i] in it, or, even more elegantly by using split()
> > function or "...chunk.." something function(), don't remember right now.
> [/snip]
> 
> Perhaps, this would remind you...  :)
> 
>$str = 'string';
>   $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
>   print_r($chars);
> ?>
> 
> That was from the manual:
>   http://www.php.net/manual/en/function.preg-split.php
> 
> - E
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Marek Kilimajer
This is working great, thank you.
Timothy's expression output one empty element at the start and the end, 
but otherwise worked ( and
I don't know why :-(

Erwin wrote:

$string = explode( '', 'string' );
 


Timothy Hitchens wrote:
 

That won't work.. empty delimiter errors always..
   


Your right, I didn't know.

 

you will have to use
my preg one from earlier...
   


But your preg thingy will only split at spaces, so that'll have to change to


$string = 'test';
preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY);
?>

in this case, right?

Grtz Erwin


 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Erwin
>> $string = explode( '', 'string' );

Timothy Hitchens wrote:
> That won't work.. empty delimiter errors always..

Your right, I didn't know.

> you will have to use
> my preg one from earlier...

But your preg thingy will only split at spaces, so that'll have to change to



in this case, right?

Grtz Erwin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread @ Edwin
Hello,


"Maxim Maletsky" <[EMAIL PROTECTED]> wrote:


[snip]
> As of actually converting it you could do that very loop and have an:
> $atr_arr[] = $str[$i] in it, or, even more elegantly by using split()
> function or "...chunk.." something function(), don't remember right now.
[/snip]

Perhaps, this would remind you...  :)



That was from the manual:
  http://www.php.net/manual/en/function.preg-split.php

- E

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Maxim Maletsky

"Erwin" <[EMAIL PROTECTED]> wrote... :

> > A string is already an array of chars
> >
> > $string = 'string';
> > echo $string[0]; // will echo 's'
> 
> True, but that's different than the array type. Sometimes you'll just need
> an array instead of a string.
> 
> Try using
> 
> $string = explode( '', 'string' );

I think this will fail. There is a function just for that, don't
remember right now what it was.


--
Maxim Maletsky
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Maxim Maletsky

String IS an array.

Basically, you could do this:

$str = 'The Dummy String';

for($i=0; $i wrote... :

> Hi all,
> 
> has anyone an elegant (and faster) way of converting 'string' to 
> array('s','t','r','i','n','g'), other then
> for($i=0; $i 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Timothy Hitchens (HiTCHO)
That won't work.. empty delimiter errors always.. you will have to use
my preg one from earlier...


Timothy Hitchens (HiTCHO)
[EMAIL PROTECTED]


If you need PHP hosting with an experienced
support team 24/7 then email me today.

On Fri, 8 Nov 2002, Erwin wrote:

> Tom Rogers wrote:
> > Hi,
> >
> > Friday, November 8, 2002, 10:43:10 PM, you wrote:
> >> Hi all,
> >
> >> has anyone an elegant (and faster) way of converting 'string' to
> >> array('s','t','r','i','n','g'), other then
> >> for($i=0; $i >
> >
> >
> > A string is already an array of chars
> >
> > $string = 'string';
> > echo $string[0]; // will echo 's'
>
> True, but that's different than the array type. Sometimes you'll just need
> an array instead of a string.
>
> Try using
>
> $string = explode( '', 'string' );
>
> Grtz Erwin
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Erwin
Tom Rogers wrote:
> Hi,
>
> Friday, November 8, 2002, 10:43:10 PM, you wrote:
>> Hi all,
>
>> has anyone an elegant (and faster) way of converting 'string' to
>> array('s','t','r','i','n','g'), other then
>> for($i=0; $i
>
>
> A string is already an array of chars
>
> $string = 'string';
> echo $string[0]; // will echo 's'

True, but that's different than the array type. Sometimes you'll just need
an array instead of a string.

Try using

$string = explode( '', 'string' );

Grtz Erwin


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Tom Rogers
Hi,

Friday, November 8, 2002, 10:43:10 PM, you wrote:
MK> Hi all,

MK> has anyone an elegant (and faster) way of converting 'string' to 
MK> array('s','t','r','i','n','g'), other then
MK> for($i=0; $ihttp://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array

2002-11-08 Thread Timothy Hitchens (HiTCHO)
Quick and Dirty:





Timothy Hitchens (HiTCHO)
[EMAIL PROTECTED]


If you need PHP hosting with an experienced
support team 24/7 then email me today.

On Fri, 8 Nov 2002, Marek Kilimajer wrote:

> Hi all,
>
> has anyone an elegant (and faster) way of converting 'string' to
> array('s','t','r','i','n','g'), other then
> for($i=0; $i
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] string to array?

2002-06-13 Thread David Freeman


 > I have a string something like "10.2.3"
 > I want to be able to use the "." as a delimiter to reference 
 > the elements (10, 2, and 3).

 > My thought was to create an array, using "." as the 
 > delimiter. Is there a function that will create an array out 
 > of a string, using a delimiter you specify?

$my_array = explode(".", "10.2.3");

--
--
Outback Queensland Internet   
Longreach ** New Web Site Online *
Queensland
Australia W: www.outbackqld.net.au


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array?

2002-06-13 Thread Analysis & Solutions

On Thu, Jun 13, 2002 at 11:17:50AM -0600, Leston Drake wrote:
> 
> I have a string something like "10.2.3"
> I want to be able to use the "." as a delimiter to reference the elements 
> (10, 2, and 3).

http://www.php.net/manual/en/function.explode.php

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] string to array??

2002-01-17 Thread Erik Price

Yes thank you, I thought I would have heard about it before now if all 
brackets were deprecated!  ;) I bit, though, when I read that page you 
linked to.

Thanks for the clarification though.


Erik



On Thursday, January 17, 2002, at 03:49  PM, Steve Edberg wrote:

> Sorry if I was less than totally clear; I was referring to this part of 
> the page:
>
> 
> Characters within strings may be accessed by specifying the zero-based 
> offset of the desired character after the string in curly braces.
>
> Note: For backwards compatibility, you can still use the array-braces. 
> However, this syntax is deprecated as of PHP 4.
>
> Example 6-3. Some string examples
>
> 
>
> /* Get the first character of a string  */
> $str = 'This is a test.'
> $first = $str{0};
> 
>
> ...and that was the first I'd noticed that myself; I assume that the {} 
> syntax is only being used to refer to arrays as strings, to avoid 
> confusion with an array of strings -
>
>   $str = array('string 1', 'thing 2');
>   echo $str[0]; # produces 'string 1'
>
> - and a scalar string variable being treated as an array of characters. 
> So I'm guessing (too lazy to test right at the moment) that you would 
> get
>
>   $str = array(array('bork','fubar'), 'snafu');
>   echo $str[0][1]; # produces 'fubar'
>   echo $str[1][1]; # produces null
>   echo $str[1]{1}; # produces 'n'
>
> Again, that's just what I'm assuming from the docs. A quick test would 
> clear it up, but it doesn't affect me right now, and I'm feeling lazy ;)
>
> Hope that clears up my statement...
>
>   -steve
>
>
> At 12:11 PM -0500 1/17/02, Erik Price wrote:
>> I didn't know that either.  Does this apply only when accessing 
>> strings by character?  Or are all conventional uses of brackets 
>> deprecated for the purposes of arrays?
>>
>> It doesn't say on that page 
>> (http://www.php.net/manual/en/language.types.string.php , a bit more 
>> than halfway down).
>>
>>
>> Erik
>>
>>>
 Actually, using the [] syntax is deprecated - using {} is the new way
 - but I'm a creature of habit...

>>
>>
>
>
> -- 
> ++
> | Steve Edberg  
> [EMAIL PROTECTED] |
> | University of California, Davis  
> (530)754-9127 |
> | Programming/Database/SysAdmin   
> http://pgfsun.ucdavis.edu/ |
> ++
> | "Restriction of free thought and free speech is the most dangerous 
> of  |
> | all subversions. It is the one un-American act that could most 
> easily  |
> | defeat 
> us."|
> | - Supreme Court Justice (1939-1975) William O. 
> Douglas |
> ++
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Steve Edberg

Sorry if I was less than totally clear; I was referring to this part 
of the page:


Characters within strings may be accessed by specifying the 
zero-based offset of the desired character after the string in curly 
braces.

Note: For backwards compatibility, you can still use the 
array-braces. However, this syntax is deprecated as of PHP 4.

Example 6-3. Some string examples



/* Get the first character of a string  */
$str = 'This is a test.'
$first = $str{0};


...and that was the first I'd noticed that myself; I assume that the 
{} syntax is only being used to refer to arrays as strings, to avoid 
confusion with an array of strings -

$str = array('string 1', 'thing 2');
echo $str[0]; # produces 'string 1'

- and a scalar string variable being treated as an array of 
characters. So I'm guessing (too lazy to test right at the moment) 
that you would get

$str = array(array('bork','fubar'), 'snafu');
echo $str[0][1]; # produces 'fubar'
echo $str[1][1]; # produces null
echo $str[1]{1}; # produces 'n'

Again, that's just what I'm assuming from the docs. A quick test 
would clear it up, but it doesn't affect me right now, and I'm 
feeling lazy ;)

Hope that clears up my statement...

-steve


At 12:11 PM -0500 1/17/02, Erik Price wrote:
>I didn't know that either.  Does this apply only when accessing 
>strings by character?  Or are all conventional uses of brackets 
>deprecated for the purposes of arrays?
>
>It doesn't say on that page 
>(http://www.php.net/manual/en/language.types.string.php , a bit more 
>than halfway down).
>
>
>Erik
>
>>
>>>Actually, using the [] syntax is deprecated - using {} is the new way
>>>- but I'm a creature of habit...
>>>
>
>


-- 
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| "Restriction of free thought and free speech is the most dangerous of  |
| all subversions. It is the one un-American act that could most easily  |
| defeat us."|
| - Supreme Court Justice (1939-1975) William O. Douglas |
++

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Erik Price



I didn't know that either.  Does this apply only when accessing strings 
by character?  Or are all conventional uses of brackets deprecated for 
the purposes of arrays?

It doesn't say on that page 
(http://www.php.net/manual/en/language.types.string.php , a bit more 
than halfway down).


Erik


>
>> Actually, using the [] syntax is deprecated - using {} is the new way
>> - but I'm a creature of habit...
>>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Erik Price

$TF_string = "Starscream, Megatron, Jetfire, Optimus Prime";
$TF_array = explode(", ", $TF_string);

print_r($TF_array);


(note the space after the comma in the first argument to "explode()", 
this necessary to avoid the space being include in each element of the 
array)

Hope that helps,

Erik


On Thursday, January 17, 2002, at 05:41  AM, Sandeep Murphy wrote:

> hi,
>
> can i convert a string to an array?? if so how shud the syntax read??
>
> Thnx,
>
> sands
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Neil Freeman

You just have to remember that a string is simply a character array :)

Nick Wilson wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> * On 17-01-02 at 12:57
> * Steve Edberg said
>
> > Actually, you can treat a string as an array without any further
> > processing:
> >
> >   $Globbot = 'dribcot';
> >   echo $Globbot[0];   # echoes 'd'
> >   echo $Globbot[6];   # echoes 't'
> >
> > Check out 'String access by character' about halfway down the page at
> >
> >   http://www.php.net/manual/en/language.types.string.php
> >
> > (or, in Portuguese,
> >
> >   http://www.php.net/manual/pt_BR/language.types.string.php
> >
> >
>
> Hmmm. I didn't know that!
>
> > Actually, using the [] syntax is deprecated - using {} is the new way
> > - but I'm a creature of habit...
> >
>
> Or that!
>
> - --
>
> Nick Wilson
>
> Tel:+45 3325 0688
> Fax:+45 3325 0677
> Web:www.explodingnet.com
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.0.6 (GNU/Linux)
>
> iD8DBQE8Rrz+HpvrrTa6L5oRAn4kAKCx41//DDBp/bPzPprs2Zls0xjGJgCgk5tz
> x16a8iDFuzEmsgSg5Iv/8Ms=
> =smoj
> -END PGP SIGNATURE-
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
> ***
>  This message was virus checked with: SAVI 3.52
>  last updated 8th January 2002
> ***

--

 Email:  [EMAIL PROTECTED]
 [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* On 17-01-02 at 12:57 
* Steve Edberg said

> Actually, you can treat a string as an array without any further 
> processing:
> 
>   $Globbot = 'dribcot';
>   echo $Globbot[0];   # echoes 'd'
>   echo $Globbot[6];   # echoes 't'
> 
> Check out 'String access by character' about halfway down the page at
> 
>   http://www.php.net/manual/en/language.types.string.php
> 
> (or, in Portuguese,
> 
>   http://www.php.net/manual/pt_BR/language.types.string.php
> 
> 

Hmmm. I didn't know that!

> Actually, using the [] syntax is deprecated - using {} is the new way 
> - but I'm a creature of habit...
> 

Or that!


- -- 

Nick Wilson

Tel:+45 3325 0688
Fax:+45 3325 0677
Web:www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE8Rrz+HpvrrTa6L5oRAn4kAKCx41//DDBp/bPzPprs2Zls0xjGJgCgk5tz
x16a8iDFuzEmsgSg5Iv/8Ms=
=smoj
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Steve Edberg

Actually, you can treat a string as an array without any further processing:

$Globbot = 'dribcot';
echo $Globbot[0];   # echoes 'd'
echo $Globbot[6];   # echoes 't'

Check out 'String access by character' about halfway down the page at

http://www.php.net/manual/en/language.types.string.php

(or, in Portuguese,

http://www.php.net/manual/pt_BR/language.types.string.php

).

Actually, using the [] syntax is deprecated - using {} is the new way 
- but I'm a creature of habit...

-steve



At 11:57 AM +0100 1/17/02, Nick Wilson <[EMAIL PROTECTED]> wrote:
>-BEGIN PGP SIGNED MESSAGE-
>Hash: SHA1
>
>
>* On 17-01-02 at 11:46
>* Sandeep Murphy said
>
>>  hi,
>>
>>  can i convert a string to an array?? if so how shud the syntax read??
>>
>>  Thnx,
>>
>>  sands
>>
>
>Check out explode()
>www.php.net/manual/en/function.explode.php
>
>- --
>
>Nick Wilson
>
>Tel:   +45 3325 0688
>Fax:   +45 3325 0677
>Web:   www.explodingnet.com
>


-- 
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| "Restriction of free thought and free speech is the most dangerous of  |
| all subversions. It is the one un-American act that could most easily  |
| defeat us."|
| - Supreme Court Justice (1939-1975) William O. Douglas |
++

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Scott Houseman

Hi There.

You should use this function:

split -- split string into array by regular expression

array split (string pattern, string string [, int limit])


So, to split a string ( e.g. a sentence ) so that each word in the string is
an element of the array do something like this



This will return:

$aMyArray[0] == 'The';
$aMyArray[1] == 'cat'; ... etc

"If limit is set, the returned array will contain a maximum of limit
elements with the last element containing the whole rest of string. "

Cheers

Scott

- Original Message -
From: "Sandeep Murphy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, January 17, 2002 12:41 PM
Subject: [PHP] string to array??


> hi,
>
> can i convert a string to an array?? if so how shud the syntax read??
>
> Thnx,
>
> sands
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] string to array??

2002-01-17 Thread Nick Wilson

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


* On 17-01-02 at 11:46 
* Sandeep Murphy said

> hi,
> 
> can i convert a string to an array?? if so how shud the syntax read??
> 
> Thnx,
> 
> sands
> 

Check out explode()
www.php.net/manual/en/function.explode.php

- -- 

Nick Wilson

Tel:+45 3325 0688
Fax:+45 3325 0677
Web:www.explodingnet.com



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)

iD8DBQE8Rq38HpvrrTa6L5oRAgzZAKCbyS8JnO4bhiTgJvEqItTSnikCPACfT1BX
OaG0cKMWM4VFouaJtF8a6vQ=
=4FtW
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]