Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP program TextColorer.php that takes a text from a textfield, colors each character
- according to its ASCII value and prints the result. If the ASCII value of a character is odd,
- the character should be printed in blue. If itβs even, it should be printed in red.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta charset="UTF-8">
- <title>Coloring Texts</title>
- <style type="text/css">
- body > p {
- font-family: "Courier New", monospace;
- font-size: 18px;
- color: #F00;
- }
- span {
- color: #00F;
- }
- </style>
- </head>
- <body>
- <form method="post">
- <textarea name="text" cols="50" rows="5" placeholder="Enter your text..."></textarea>
- <p><input type="submit" value="Color text"/></p>
- </form>
- <p>
- <?php
- mb_internal_encoding('UTF-8');
- if (!isset($_POST) || !isset($_POST['text']) || trim($_POST['text']) === '') {
- die("The Input Form can't been Empty!!!");
- }
- $textArr = str_split(trim($_POST['text']));
- foreach ($textArr as $char) {
- if (ord($char) % 2 !== 0) {
- echo '<span>' . $char . ' </span>';
- } else {
- echo $char . ' ';
- }
- }
- ?>
- </p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement