在一定数量的字符后插入断点

How do I insert break point after certain number of break points

Like my string is ' Celebrating Founder’s Day ' and I call function to insert break point after 6 characters means it should return me ' Celebrating
Founder’s Day ' it should take the nearest space to insert the break point not at the character length given.

    if ( mb_strlen( $str) > $charlength ) {
        $subex = mb_substr( $str, 0, $charlength - 5 );
        $exwords = explode( ' ', $subex );
        $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
        if ( $excut < 0 ) {
            echo mb_substr( $subex, 0, $excut );
        } else {
            echo $subex;
        }
    } else {
        echo $str;
    }

I did not understand how to change this to insert the break point after certain characters

This code extracts the string of given character length

I did not understand this code to modify to insert break point after certain number of character length..

Have not tried but basic logic:

function breakPoint($string, $offset) {
    $place  = strpos($string, ' ', $offset);
    if($place !== false) {
        return substr($string, 0, $place)."
".substr($string, $place+1);
    }

    return $string;
}

You should look for strpos function.