Jump to content

Uninitialized String Offset: 52


dennismonsewicz

Recommended Posts

I have a function that takes a string and splits it up into two parts... well I keep running into the issue of Uninitialized String Offest: 52... but it only happens when the string is more than the specified length..

 

function string_into_parts($text, $length=45) {
            $text = trim($text);
            $array = array();
            if(strlen($text) > $length) {
                for($i=0;$text[$length+$i]!=" ";$i++) {
                    if(!$text[$length+$i]) {
                        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;
    }

 

Any help is much appreciated!!!!

Link to comment
https://forums.phpfreaks.com/topic/199876-uninitialized-string-offset-52/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.