dennismonsewicz Posted April 29, 2010 Share Posted April 29, 2010 I have the following function: function string_into_parts($text, $length=45) { $text = strval(trim($text)); $array = array(); $counter = 0; if(strlen($text) > $length) { for($i=0;$text[$length+$i]!=" ";$i++) { //line 67 if(!$text[$length+$i]) { //line 68 return $text; } } $array['firstHalf'] = trim(substr($text,0,$length+$i)); $array['secondHalf'] = trim(substr($text,$length+$i)); } else { $array['firstHalf'] = $text; $array['secondHalf'] = ''; } return $array; } but if you run it on a string that contains an individual number, IE: it broke into 2 pieces, the script fails and I receive the Uninitialized string offset error message. The script fails at lines 67 & 68. Anyone know why this could be failing? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
teamatomic Posted April 29, 2010 Share Posted April 29, 2010 Nothings wrong with the code. Just seems like a lot of lines to do just this: $length=45; $str='this is a test for the string length split it should work just fine with a lot less code'; $max=strlen("$str"); $sub1=substr("$str", 0, "$length"); $sub2= substr("$str", "$length","$max" ); echo "$sub1::$sub2"; HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted April 29, 2010 Author Share Posted April 29, 2010 This works perfect!!!!!! Thank you SOOO MUCH! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.