forked from obetancourthunicah/IF412NegociosWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEjercicio4.php
65 lines (65 loc) · 1.78 KB
/
Ejercicio4.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
<?php
$result = "";
$txtOrg = "";
// +3 Elia
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);
$txtOrg = str_replace(" "," ",$txtOrg);
//preg_replace remplazar mendiante 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 $palabrak=>$freq){
$result = "La palabra << $palabrak >> con mayor frecuencia de : $freq";
break;
}
}else{
$result="No hay palabras que analizar";
}
//associative reverse sort
//asort();
//associative sort
//para depuracion
//print_r($arregloFrecuencias);
//die();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Ejemplo de Uso de Arreglos Xtreme</title>
<meta charset="utf-8"/>
</head>
<body>
<h1>Stats de Blogs</h1>
<form action="bb.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>