Skip to content

Instantly share code, notes, and snippets.

@lablnet
Created November 30, 2019 06:21
Show Gist options
  • Select an option

  • Save lablnet/a0ca1bfd63de3fd1f951d2acbf6bd878 to your computer and use it in GitHub Desktop.

Select an option

Save lablnet/a0ca1bfd63de3fd1f951d2acbf6bd878 to your computer and use it in GitHub Desktop.
<?php
if (isset($_POST['submit'])) {
$text = (null !== empty(trim($_POST['text']))) ? stripslashes(trim(htmlentities(htmlspecialchars(strip_tags($_POST['text']), ENT_QUOTES | ENT_HTML5, 'UTF-8'), ENT_QUOTES | ENT_HTML5, 'UTF-8'))) : '';
if ('' !== $text) {
$spilt = explode(' ', $text);
echo "<strong>Counts:</strong><br/ >";
foreach (array_unique($spilt) as $key => $value) {
$count = substr_count($text, $value);
echo "<b>$value:</b> <i>$count</i> <br>";
}
echo "<strong>Original:</strong> ".$text . '<br>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP test task</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>PHP test task</h2>
<form action="" method="post">
<div class="form-group">
<label for="text">Text:</label>
<textarea class="form-control" rows="5" name="text" id="text"></textarea>
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment