Welcome Guest, Not a member yet? Register   Sign In
how to split a string
#1

[eluser]megabyte[/eluser]
I have tried a bunch of solutions and the only one htat seems to keep the punctuation and html is the CI function word_limiter, but I can't seem to get it to return both parts.

You know how it returns a portion of the string?


Well I want it to return an array including the limit and the remaining part of the string.


anyone help me out please?

I modified word_limiter() to this:

Code:
function split_content($str)
    {
        
        echo str_word_count($str);
        
        $limit = str_word_count($str) / 2;
        
        echo $limit;
        
        if (trim($str) == '')
        {
            return $str;
        }
    
        preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/', $str, $match);
        
        $matches[0] = $match[0];
        $matches[1] = str_replace($matches[0], '', $str);
        
        return $matches;
    }


but there must be a better way


Messages In This Thread
how to split a string - by El Forum - 10-12-2009, 06:27 PM
how to split a string - by El Forum - 10-12-2009, 06:36 PM
how to split a string - by El Forum - 10-12-2009, 06:45 PM
how to split a string - by El Forum - 10-12-2009, 06:48 PM
how to split a string - by El Forum - 10-12-2009, 06:55 PM
how to split a string - by El Forum - 10-12-2009, 07:01 PM
how to split a string - by El Forum - 10-12-2009, 07:07 PM
how to split a string - by El Forum - 10-12-2009, 07:24 PM
how to split a string - by El Forum - 10-12-2009, 07:53 PM
how to split a string - by El Forum - 10-13-2009, 05:32 AM
how to split a string - by El Forum - 10-13-2009, 09:29 AM
how to split a string - by El Forum - 10-13-2009, 05:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB