for ($i = 0; $i < mb_strlen($in); $i++) { if ($i > 350 && mb_substr($in, $i, 1) == '.') { $endstr = mb_substr($in, $i + 1); $endstr = preg_replace("/^\s*/u", '', $endstr); $in = mb_substr($in, 0, $i) . ".\n" . $endstr; break; } } 

Who is less? The essence of this process is to make a transfer from the text after about 350 characters, after the first point. This is a very terrible construction.

Thank.

  • Damn, yes! $ in = preg_replace ("/ (. {150} [^ \.] * \.) \ s * / u", "$ 1 \ n", $ in); For a long time I could not get to this regular season. Thank !!!!! - jkeks
  • Apparently, ignorance of the possibilities of deep optimization in the interpreter of PCP plunges me into a deep dismay at the sight of if checking the length of the string inside for for at each step which is calculated by calling the function this length ... And can everything be easier? Do iron producers pay extra to authors of a similar code (or their teachers)? By the way, using preg_replace () to solve this problem is also from the same area. - avp
  • @avp Hobbies: Conspiracy? - alexlz
  • No, just a clumsy attempt to shame such writers. - avp
  • I love single-line solutions, even if they are indestructible in speed, so how can you properly implement the task of yours? if it is not the odds and preg_replace, what? - jkeks

1 answer 1

/(.{200}[^.]*\.)\s*/u swap to $1\n