Problema script justificado
Publicado por gatoher (3 intervenciones) el 31/08/2012 22:29:03
Hola a todos, tengo un problema con un script que sirve para justificar texto. La verdad, que lo he repasado unas 20 veces y no le veo el error. En el navegador me da error en línea 54, pero ahi no le veo nada.
Alguien que pueda ver que ocure aqui.
Gracias
Alguien que pueda ver que ocure aqui.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Justifying Lines of Text</title>
<link rel="stylesheet" type="text/css" href="comon.css" />
</head>
<h1>Justifying Lines of Text </h1>
<?php
// EL TEXTO A JUSTIFICAR
$mytext=<<< END_TEXT
But think not that this famous town has
only harpooners, cannibals, and
bumpkins to show her visitors. Not
at all. Still New Bedford is a queer place.
Had it not been for us whalemen, that
tract of land would this day perhaps
have been in as howling condition as the
coast of Labrador.
END_TEXT;
$mytext = str_replace ("\r\n", "\n", $mytext);
$linelength = 40; //LONGITUD DE LA LINEA DESEADA
$mytextjustified = "";
$numlines = substr_count($mytext, "\n");
$startofline = 0;
//MOVERSE POR CADA LINEA A LA VEZ
for ( $i = 0; $i <$numlines; $i++) {
$originallinelength = strpos ($mytext, "\n", $startofline) - $startofline;
$justifiedline = substr ( $mytext, $startofline, $originallinelength);
$justifiedlinelength = $originallinelength;
// SEGUIR AÑADIENDO ESPACIOS ENTRE LAS PALABRAS HASTA QUE SE ALCANCEN
// LA LONGITUD DE LA LINEA DESEADA
while ( $i <$numlines -1 && $justifiedlinelength <$linelength ) {
for ( $j=0; $j <$justifiedlinelength; $j++ ) {
if ($justifiedlinelength < $linelength && $justifiedline [$j] == "" ) {
$justifiedline = substr_replace ( $justifiedline, " ", $j, 0 );
$justifiedlinelength ++;
$j++;
}
}
}
// AÑADIR LA LINEA JUSTIFICADA A LA CADENA Y DESPLAZARSE AL
// INICIO DE LA LINEA SIGUIENTE
$mytextjustified .= "$justifiedline\n";
$startofline += $originallinelength +1;
}
?>
<h2>Original text: </h2>
<pre><?php echo $mytextjustified ?></pre>
</body>
</html>
Gracias
Valora esta pregunta
0