-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexto.php
More file actions
79 lines (69 loc) · 1.76 KB
/
Copy pathTexto.php
File metadata and controls
79 lines (69 loc) · 1.76 KB
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
<?php
class Texto
{
public $text;
/**
* Permite inicializar el objeto con un texto en especifico, en caso de que no se defina con el constructor es posible llamar
* al metodo setText.
*
* @param [string] $text
*/
public function __construct( $text = null )
{
$this->setText($text);
}
/**
* define el texto con el cual va a trabajar la clase
*
* @param [string] $text
*
* @return
* true si es posible asignar el texto, false en caso contrario
*/
public function setText( $text )
{
if( is_string($text) )
{
$this->text = $text;
return true;
}
else
{
return false;
}
}
/**
* Cuenta las veces que se repite el caracter pasado como el primer argumento en el texto indicado como segundo argumento. El
* caracter puede ser UTF-8.
*
* @param [string] $char
*
* @return
* Retorna un valor entero que representa el numero de veces
*/
public function countChar( $char )
{
$tamano_del_texto = strlen($this->text);
$contador = 0;
for($i = 0; $i < $tamano_del_texto; $i++)
{
if( $char == $this->text[$i])
$contador++;
}
return $contador;
}
/**
* Cuenta el numero de palabras que hay en el texto.
*
* @return void
*/
public static function countWords( )
{
// mapOfWords es un diccionario (clave => valor) en donde se almacenara cada palabra con su respectivo conteo de veces
// que se repite en el texto.
$mapOfWords = array();
}
}
$text = new Text();
$text->text = "etsa es una prueba";
echo $text->countChar('n');