Web Hosting Talk







View Full Version : question about str_split() function


latheesan
10-02-2007, 12:20 PM
Hello,

I was working on a project on my laptop, which had latest XAMPP installed on it, so i was using PHP 5.

In my script, i was using this function str_split() to split really long string into smaller chunks like this (for example):

$arr = str_split("abcdefghijklmnopqrstuvwxyz",3);

Then when i was finished with my script, i uploaded it to my linux server and it seems my host is using php 4.4, so im starting to get this error:

Fatal error: Call to undefined function: str_split() in /home/admin/domains/mydomain.com/public_html/index.php on line 60

Is there a similar function as split_str() in PHP 4 or can i acheive this some other way?

orbitz
10-02-2007, 02:28 PM
go to: http://us3.php.net/str_split
roll down to a post by kjensen at iaff106 dot com.
He wrote the function for php 4.

isurus
10-02-2007, 02:44 PM
You could use chunk_split:
<?php
$chunks = chunk_split( "abcdefghijklmnopqrstuvwxyz", 3, "," );
$chunks = substr( $chunks, 0, (strlen( $chunks )-1) ); // strip off the trailing ,
$chunk_arrays = explode( ',', $chunks );
print_r( $chunk_arrays );

$chunk_arrays = str_split( "abcdefghijklmnopqrstuvwxyz", 3 );
print_r( $chunk_arrays );
?>

latheesan
10-02-2007, 05:43 PM
Thanks allot isurus, it works great :)