Thanks to Richard who pointed me in the right direction. I failed to notice 
that the str_split function is only for use with php v5, I was run 
4.3.10...DOH!

In case anyone what the solution here is a rewrite.....
////////////////////////////////////
<?PHP
 $test='this is test';
 $test2=Array();
 echo $test;
 echo '<br>ping 1<br>';
 $strSize=strlen($test);
 for($i=0;$i<$strSize;$i++)
 {
  array_push($test2,$test[$i]);
 }
 echo 'ping 2<br>';
 for($i=0;$i<$strSize;$i++)
 {
  echo $test2[$i].'<br>';
 }
?>
////////////////////////////////////

This will correctly produce
////////////////////////////////////
this is test
ping 1
ping 2
t
h
i
s

i
s

t
e
s
t
////////////////////////////////////
Jochem, thanks for pointing out the count inside the loop issue. This is a 
good point to remember...

Thank,
Chris

"Jochem Maas" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> chris wrote:
>> No good.
>
> this should work, I rewrote you little test and no probs (as expected):
>
>  php -r '
>
> $test = "this is test";
> echo $test,"\n";
> $test2 = str_split($test);
> foreach($test2 as $s) {
>     echo $s."\n";
> }
>
> '
>
>
>>
>> I made the change to this (note the echo ping statements)
>> /////////////////// start
>> <?PHP
>>  $test='this is test';
>>  echo $test;
>>  echo '<br>ping 1<br>';
>>  $test2=str_split($test);
>
> long shot: try specifying the second param to str_split()
> e.g.:
>
> $test2=str_split($test,1);
>
> if that doesn't do it you can probably consider you php install borked - 
> in which case reinstall!
>
>>  echo 'ping 2<br>';
>>  echo '<pre>';
>>  for($i=0;$i<count($test2);$i++)
>
> while we're at it - don't put the count statement inside the loop, they 
> way you have it now count() gets called on every iteration - thats 
> wasteful. also notice the foreach syntax I used above, it will save to 
> time in typing :-) (I believe its faster for simple array iteration as 
> well - anyone care to correct?)
>
>>  {
>>   print_r($test2[$i]);
>>  }
>>  echo '</pre>';
>> ?>
>> /////////////////// end
>>
>> result is now
>> /////////////////
>> this is test
>> ping 1
>> /////////////////
>>
>> "Greg Donald" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>
>>>On Fri, 21 Jan 2005 12:07:34 -0600, chris <[EMAIL PROTECTED]> wrote:
>>>
>>>> $test2=str_split($test);
>>>
>>>Do echo '<pre>'; print_r( $test2 ); right here and see if the $test2
>>>array has the data you expect.
>>>
>>>
>>>-- 
>>>Greg Donald
>>>Zend Certified Engineer
>>>http://destiney.com/
>>
>>
>>
>> ---
>> Outgoing mail is certified Virus Free.
>> Checked by AVG anti-virus system (http://www.grisoft.com).
>> Version: 6.0.817 / Virus Database: 555 - Release Date: 12/15/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.817 / Virus Database: 555 - Release Date: 12/15/2004 

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

Reply via email to