Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: min(seven, seven)?
(Example: nine)

The Note You're Voting On

waage
17 years ago
I had some issues trying to get both word wrapping and new line detection but with some of the help from the comments below i got this. (thanks to jwe for the main part of the code here)

<?php
function ttfWordWrappedText($text, $strlen = 38) {
$text = urldecode($text);
$text = explode("\n", $text);

$i = 0;
foreach(
$text as $text)
{
while(
strlen($text) > $strlen) {
$startPoint = $strlen - 1;
while(
substr($text, $startPoint, 1) != " ") {
$startPoint--;
}
$line[$i][] = trim(substr($text, 0, $startPoint));
$text = substr($text, $startPoint);
}
$line[$i][] = trim($text);
$i++;
}

return
$line;
}
?>

This returns an array for each newline entered and subarray for each wordwrapped line to print.

ie.

Array
(
[0] => Array
(
[0] => This is the first long line
[1] => that i entered.
)

[1] => Array
(
[0] => And this is the new line after that.
)
)

<< Back to user notes page

To Top