Created
October 21, 2018 04:24
-
-
Save phpfiddle/418c3239a4d2e85be8cea7fd0782af66 to your computer and use it in GitHub Desktop.
[ Posted by Martin ] Word analysing in texts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$analyze = ''; | |
$punctuations = '.:-,;–_?!'; | |
if (isset($_POST['analyze']) and trim($_POST['analyze']) != '') { | |
$analyze = $_POST['analyze']; | |
$analyzed = preg_replace( "/\r|\n/", " ", $analyze ); | |
$len = strlen($analyze); | |
$pl = strlen($punctuations); | |
for ($i=0; $i < $pl; $i++) { | |
$analyzed = str_replace($punctuations[$i], ' ', $analyzed); | |
} | |
$words = array_filter(explode(' ', $analyzed)); | |
$result = [ | |
'characters' => $len, | |
'count' => count($words), | |
'differents' => count(array_unique($words)), | |
]; | |
echo '<pre>' . print_r($result, true) . '</pre>'; | |
} | |
?> | |
<!-- Your forms --> | |
<form action="" method="POST" class="myForm"> | |
<textarea placeholder="Dein Text" name="analyze" style="width: 100%;" rows="10"><?php echo $analyze; ?></textarea> | |
<input type="submit" id="submit" value="analysieren" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment