G
G
glem13372018-10-08 20:58:40
PHP
glem1337, 2018-10-08 20:58:40

Why does Lebedev's typographer return an error?

I use Lebedev's typographer on my test project , it has a limited size of accepted text.
I want to try breaking up the HTML into parts.
I wrote a recursive function, however, sometimes it gives this error. As I understand it, these are two broken lines. 5bbb9a2408a29588437046.pngsometimes - everything is fine, often this happens if you make some changes, for example, delete one word.
Function code:

public function get_typograph_content( $content ) {

    $remoteTypograf = new RemoteTypograf();
    $remoteTypograf->br (false);
    $remoteTypograf->p (false);
    $remoteTypograf->nobr (3);
    $remoteTypograf->quotA ('laquo raquo');
    $remoteTypograf->quotB ('bdquo ldquo');

    $contentSize = strlen($content);

    if ( $contentSize < 32000 ) {
      $content = $remoteTypograf->processText( $content );
      return $content;
    } else {
      $firstPart = substr($content, 0, $contentSize/2);
      $lastPart = substr($content, $contentSize/2);
      $content = $this->get_typograph_content( $firstPart );
      $content .= $this->get_typograph_content( $lastPart );
      //var_dump($content);
      return $content;
    }

  }

Do I understand correctly that the problem is in my function, and not in the typographer? Do I need to not just break HTML, but use a parser to break HTML into blocks and then process it with a typographer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2018-10-09
@SilenceOfWinter

Check the text encoding, if multibyte strings, then use mb_* analogues of functions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question