0

リンクされたブロックが 2 つあるという問題があります。最大文字数になると(縮小して収まる前に)、次のリンクされたブロックに移動します。問題は、次のブロックに大量のテキストがプッシュされると、非常に小さくなることです。すべての文字を均等に各ボックスに分割する方法はありますか? 縮んでも大丈夫、同じように見えればいいんです。以下の例の画像とコード:

http://i.imgur.com/ytadphF.png

public function addTextToMultiBlock($text,$baseBlockName,$numberOfBlocks)
{
    $tf = 0;
    for ($i = 1; $i <= $numberOfBlocks; $i++)
    {
        $optlist ="encoding=unicode textflowhandle=" . $tf;
        $tf = $this->p->fill_textblock($this->page, $baseBlockName.$i, $text, $optlist);
        //Set text to null ( $tf handle holds extra text from now on )
        $text = null;
        if ($tf == 0) {
         trigger_error("Warning: " . $this->p->get_errmsg() . "\n");
         break;
        }
    $reason = (int) $this->p->info_textflow($tf, "returnreason");
    $result = $this->p->get_parameter("string",  $reason);
    //Break if all text is placed
     if ($result == "_stop")
        {
            $this->p->delete_textflow($tf);
           break;
        }
    }
}

//call below to block
    if(!empty($this->orderData->remarks))
    {
    $addRemarks.= $this->orderData->remarks;
    $helper->addTextToMultiBlock($this->orderData->remarks, 'info', 2);
    }
    else
    {
        //nothing
    }
4

2 に答える 2

0

私が考えているのは、単語を数えることです:

<?php

// SET THE NUMBER OF BOXES YOU WANT
$boxes = 2;

// SAMPLE INPUT STRING
$string = 'Life it seems to fade away, drifting further every day.  Getting lost within myself.  Nothing matters no one else.';

// MATCH EACH WORD AND STORE IT INTO AN ARRAY
preg_match_all('/\S+/', $string, $matches);

// COUNT HOW MANY WORDS WE HAVE TOTAL
$word_count = count($matches[0]);

// DIVIDE THE TOTAL WORDS BY THE NUMBER OF BOXES
// TO FIND HOW MANY WORDS WE SHOULD HAVE IN EACH BOX
$words_per_box = round($word_count / $boxes);

// SPLIT THE ARRAY OF WORDS INTO CHUNKS BASED ON THE
// - NUMBER OF WORDS PER BOX THAT WE SHOULD HAVE   
$chunks = array_chunk($matches[0], $words_per_box);

// START OUTPUTTING THE TABLE
print '
    <table border=1 cellpadding=5 cellspacing=0>
    <tr>';

// LOOP THROUGH EACH CHUNK OF WORDS AND TURN IT BACK
// - INTO A STRING THAT WE CAN PRINT OUT
foreach ($chunks AS $word_block) {
    //PRINT BLOCK TEXT
    print '
      <td>'.implode(' ', $word_block).'</td>';  
}

// CLOSE OUT THE TABLE
print '
    </table>';

これにより、次が出力されます。

<table border="1" cellpadding="5" cellspacing="0">
<tr>
  <td>Life it seems to fade away, drifting further every day.</td>
  <td>Getting lost within myself. Nothing matters no one else.</td>
</table>

これは完璧な解決策ではありませんが、うまくいけば、かなり近づくことができます.

于 2014-03-17T18:08:12.107 に答える