hi
the following function is flawed because it uses words instead of charactors. i want to change it so that it looks at the number of chars and uses a char limit per sentence and works that way instead of words. bearing in mind that a sentence cannot break in the middle of a word -- thats the difficulty im having. please see if you can rewrite any of this to the way i am stating. thank you!
function splitSentence($theWord, $num_words, $x, $y, $handle, $cheque = 0) {
2 if (!is_numeric($num_words)){
3 echo "this value is supposed to be a number!";
4 }
5 //$theWord = "one two three four five six seven eight";
6
7 $text = trim($theWord);
8 $words = explode(" ",$text);
9
10 //get the total number of words
11 $num_elements = count($words);
12 // echo "the number of words: ".$num_elements."<BR>";
13
14 //figure out the total number of sentences to create
15 //use the modulus operator to check the remainder of the division of words array by the number of words/sentence
16 if (($num_elements % $num_words)>0){
17 //if there are more than an evenly dividable set of numbers
18
19 $tot_sent=(int)(($num_elements / $num_words)+1);
20 }else{
21 //evenly dividable
22 $tot_sent=($num_elements / $num_words);
23 }
24
25 //assume from your description that you want to create / fill the sentence array before echoing back to the browser
26 //fill sentence array
27
28 //$yy is a counter
29 for($yy=0; $yy<$tot_sent; $yy++){
30
31 //change the position of the array pointer to continue with the next words in the array
32 if ($yy>0){
33 $zz=$num_words*$yy;
34 }else{
35 $zz=0;
36 } // end if
37
38
39 //loop through the $words array and place into sentence
40 for($qq=(0);$qq<$num_words;$qq++){
41 // echo $words[$qq];
42 //fill the sentence
43 $sentence[$yy]=$sentence[$yy].$words[$qq+$zz]." ";
44 //echo $sentence[$yy];
45 } //end $qq for loop
46
47 } // end $yy for loop
48
49 //show the sentences
50 for ($ii=0; $ii<$tot_sent; $ii++){
51
52 $the_sentence=trim($sentence[$ii]);
53 // echo $the_sentence."<br>";
54
55 printer_draw_text($handle, $the_sentence, $x, $y);
56
57 if ($cheque == 0) {
58 $y = $y+100; // set the coordinates for the next line
59 } else {
60 // then cheque must be 1 so increase the gap width for cheque
61 $y = $y+250;
62 }
63
64
65 } //close the loop
66
67
68 } // end function
69