Anonymous user
Pangram checker: Difference between revisions
→{{header|PHP}}
(Adding Fōrmulæ) |
|||
Line 1,958:
ABCDEFGHIJKL.NOPQRSTUVWXYZ : F
ABC.D.E.FGHI*J/KL-M+NO*PQ R STUVWXYZ : T
</pre>
Using array
<lang php>function is_pangram( $sentence ) {
// define "alphabet"
$alpha = range( 'a', 'z' );
// split lowercased string into array
$a_sentence = str_split( strtolower( $sentence ) );
// check that there are no letters present in alpha not in sentence
return empty( array_diff( $alpha, $a_sentence ) );
}
$tests = array(
"The quick brown fox jumps over the lazy dog.",
"The brown fox jumps over the lazy dog.",
"ABCDEFGHIJKL.NOPQRSTUVWXYZ",
"ABC.D.E.FGHI*J/KL-M+NO*PQ R\nSTUVWXYZ",
"How vexingly quick daft zebras jump",
"Is hotdog?",
"How razorback-jumping frogs can level six piqued gymnasts!"
);
foreach ( $tests as $txt ) {
echo '"', $txt, '"', PHP_EOL;
echo is_pangram( $txt ) ? "Yes" : "No", PHP_EOL, PHP_EOL;
}
</lang>
{{Out}}
<pre>
"The quick brown fox jumps over the lazy dog."
Yes
"The brown fox jumps over the lazy dog."
No
"ABCDEFGHIJKL.NOPQRSTUVWXYZ"
No
"ABC.D.E.FGHI*J/KL-M+NO*PQ R
STUVWXYZ"
Yes
"How vexingly quick daft zebras jump"
Yes
"Is hotdog?"
No
"How razorback-jumping frogs can level six piqued gymnasts!"
Yes
</pre>
|