-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathej4.php
72 lines (62 loc) · 1.89 KB
/
ej4.php
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
<?php
$result = "";
$txtorg = "";
if(isset($_POST["btnprc"])){
$txtorg = strtolower($_POST["txtorg"]);
$txtorg = str_replace(".","",$txtorg);
$txtorg = str_replace(",","",$txtorg);
$txtorg = str_replace("?","",$txtorg);
$txtorg = str_replace("!","",$txtorg);
$txtorg = str_replace("¿","",$txtorg);
$txtorg = str_replace("¡","",$txtorg);
// preg_replace reemplaza mediante expresiones regulares
$arreglopalabras= explode(" ", $txtorg);
$arreglofrecuencias = array();
foreach($arreglopalabras as $palabra){
if(isset($arreglofrecuencias[$palabra])){
$arreglofrecuencias[$palabra] ++;
}else{
$arreglofrecuencias[$palabra] = 1;
}
}
if(is_array($arreglofrecuencias)
&& count($arreglofrecuencias) > 0 ){
arsort($arreglofrecuencias);
foreach($arreglofrecuencias as $palabra => $freq){
$result = "la palabra con mayor frecuencia de $freq ";
break;
}
$result = "aqui la palabra y mayor frecuencia";
}else{
$result = "no hay palabra que analizar";
}
//arsort(); associative reverse sort
//asort(); associative sort
//para depuracion
print_r($arreglofrecuencias);
die();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<title>Ejericico uso de arreglos Xtreme</title>
</head>
<body>
<h1>Stats de Blogs</h1>
<form action="ej4.php" method="post">
<label for="txtorg"> Texto de un blog</label>
<br/>
<textarea id="txtorg" name="txtorg">
<?php echo $txtorg; ?>
</textarea>
<br/>
<input type="submit" id="btnprc"
name="btnprc" value="procesar" />
</form>
<div>
<?php echo $result; ?>
</div>
</body>
</html>