Allora ecco un esempio da come vedo la cosa. Ci sono delle migliorie da fare tipo finire con una parola intera... ma comunque l'idea c'è.
codice:
<?
//----------------- Testo
$testo_originale = <<<HDO
PHP takes expressions much further, in the same way many other languages do.
PHP is an expression-oriented language, in the sense that almost everything
is an expression. Consider the example we've already dealt with,
'\$a = 5'. It's easy to see that there are two values involved here, the
value of the integer constant '5', and the value of \$a which is being
updated to 5 as well. But the truth is that there's one additional value
involved here, and that's the value of the assignment itself. The assignment
itself evaluates to the assigned value, in this case 5. In practice, it means
that '\$a = 5', regardless of what it does, is an expression with the value 5.
Thus, writing something like '\$b = (\$a = 5)' is like writing '\$a = 5; \$b = 5;'
(a semicolon marks the end of a statement). Since assignments are parsed in a
right to left order, you can also write '\$b = \$a = 5'.
Another good example of expression orientation is pre- and post-increment and
decrement. Users of PHP and many other languages may be familiar with the
notation of variable++ and variable--. These are increment and decrement
operators. In PHP/FI 2, the statement '\$a++' has no value (is not an expression),
and thus you can't assign it or use it in any way. PHP enhances the increment/decrement
capabilities by making these expressions as well, like in C. In PHP, like in C,
there are two types of increment - pre-increment and post-increment.
Both pre-increment and post-increment essentially increment the variable,
and the effect on the variable is identical. The difference is with the value
of the increment expression. Pre-increment, which is written '++\$variable',
evaluates to the incremented value (PHP increments the variable before reading
its value, thus the name 'pre-increment'). Post-increment, which is written
'\$variable++' evaluates to the original value of \$variable, before it was
incremented (PHP increments the variable after reading its value, thus the
name 'post-increment').
HDO;
?>
<h4>Lunghezza testo <? print strlen($testo_originale) ?></h4>
<?
//----------------- Inizializzazione
$maxchar = 500;
$pagine = array();
//----------------- Split del testo originale
$testo = $testo_originale;
$end = false;
while (!$end) {
if (strlen($testo) <= $maxchar) {
$pagine[] = $testo;
$end = true;
} else {
$pagine[] = substr($testo,0,$maxchar);
$testo = substr($testo,$maxchar,strlen($testo));
} // if (strlen($testo) <= $maxchar)
} // while (!$end)
//----------------- Costruzione dei link
$numeroPagine = count($pagine);
if ($numeroPagine > 1) {?>
Pagina :<?
for ($i=0;$i<$numeroPagine;$i++) {?>
<? print $i+1 ?><?
} // for ($i=0;$i<$numeroPagine;$i++)
} // if ($numeroPagine > 1)
//---------------- Adesso guardo la pagina da visualizzare
$pagina_da_visualizzare = 0;
if (isset($_GET['page'])) {
$pdv = $_GET['page'];
if (is_numeric($pdv)) {
if ($pdv >=0 and $pdv <= $numeroPagine) {
$pagina_da_visualizzare = $pdv - 1;
} // if ($pdv >=0 and $pdv < $numeroPagine)
} // if (is_numeric($pdv))
} // if (isset($_GET['page']))
$testo_da_visualizzare = $pagine[$pagina_da_visualizzare];
?>
<div style="background-color:#ffffcc;font-family:verdana;font-size:9pt;width:600;height:250">
<? print $testo_da_visualizzare ?>
</div>
Testo per pagina :
<?
for ($i=0;$i<$numeroPagine;$i++) {?>
<div style="background-color:#ff9966;font-family:verdana;font-size:9pt;">
<?
print $i == $pagina_da_visualizzare ? "".$pagine[$i]."" : $pagine[$i];
} // for ($i=0;$i<$numeroPagine)
?>