PHP - Problema script justificado

 
Vista:
sin imagen de perfil

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.

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
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.943
Oro
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

Problema script justificado

Publicado por xve (6935 intervenciones) el 01/09/2012 07:48:50
Hola gatoher, porque no utilizas el estilo text-align:justify;?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problema script justificado

Publicado por gatoher (3 intervenciones) el 02/09/2012 20:06:17
Hola xve, ya se , pero se trata de hacerlo con PHP.,estoy estudiando eso. Me gustaría que me comentaras lo de la secuencia de imagenes, me gustaría usarlo para una web que estoy haciendo y me he quedado atascado. ¿Te funciana a ti el script?. La verdad es que lo necersito.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Problema script justificado

Publicado por gatoher (3 intervenciones) el 03/09/2012 10:32:57
Si xve, en el foro de javascript esta puesto el hilo. No me llegaba a funcionar.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar