I found this code that will contain no more than 300 characters, and then break in the next closest break word:
$var = 'This is a test text 1234567890 test check12.'
preg_match('/^.{0,300}(?:.*?)\b/iu', $var, $matches);
echo $matches[0];
44 is less than 300, so I expect the result to be the same as $ var.
But the way out:
This is a test text 1234567890 test check12
$ matches [0] doesn't give me a dot at the end, however $ var does. Can anyone tell me how to get the complete line (with dot)?
source
share