I found this code which will match at most 300 chars, then break at the next nearest word-break:
$var = 'This is a test text 1234567890 test check12.' # 44 chars
preg_match('/^.{0,300}(?:.*?)\b/iu', $var, $matches);
echo $matches[0];
44 is lower than 300, so I expect the output to be the same like $var.
But the output is:
This is a test text 1234567890 test check12 # 43 chars
$matches[0] is not giving me the dot at the end, however $var does. Anyone can tell me how to get the full string (with the dot)?