Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 21, 2020 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/f4003a8c338d244ab028e6bae91d3c69 to your computer and use it in GitHub Desktop.
Save parzibyte/f4003a8c338d244ab028e6bae91d3c69 to your computer and use it in GitHub Desktop.
<?php
/*
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
Copyright (c) 2020 Luis Cabrera Benito
Licenciado bajo la licencia MIT
El texto de arriba debe ser incluido en cualquier redistribucion
*/ ?>
<?php
$texto = "Programar en PHP es realmente sencillo, como contar del 1 al 10";
echo "Contando letras de: '$texto'\n";
$letras = "abcdefghijklmnopqrstuvwxyz";
$letras .= strtoupper($letras);
for ($i = 0; $i < strlen($letras); $i++) {
$letra = $letras[$i];
$contador = 0;
for ($x = 0; $x < strlen($texto); $x++) {
$actual = $texto[$x];
if ($actual === $letra) {
$contador++;
}
}
if ($contador > 0) {
echo "$letra=";
echo $contador;
echo "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment