Skip to content

Instantly share code, notes, and snippets.

@sareiodata
Created February 20, 2018 08:47
Show Gist options
  • Save sareiodata/9cbf0474d41b65a4acb90f1af3b30557 to your computer and use it in GitHub Desktop.
Save sareiodata/9cbf0474d41b65a4acb90f1af3b30557 to your computer and use it in GitHub Desktop.
<?php
function word_hash($str){
$hash =0;
$str = str_split($str);
foreach($str as $key => $char){
$hash += ord($char) * $key;
}
return $hash;
}
function generateRandomString($length = 30) {
$characters = ' tttttttttttttttttttttttttttttttttooooooooooooooooooooooooooooooeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrriiiiiiiiiiiiiiiiiiiinnnnnnnnnnnnnnnnnnnnssssssssssssssssuuuuuuuuuuuuuuulllllllllllllllcccccccccchhhhhhhhhyyyyyyyywwwwwwwwbbbbbbbbddddddddfffffffppppppmmmmmmgggggg..vvkk7;18&#!2';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
function avg($str)
{
$words = explode(' ', $str );
$hash = array();
foreach ($words as $key => $word) {
$hash[] = word_hash($word);
}
return $hash;
}
$str1 = "I know all of these represent a lot of information and it would take a while to apply them all, but the bottom line is that marketing is also important for growing your products and achieve the business goals you&#8217;ve set out. Any actionable tactic will sure bring traffic to your website and grow the brand awareness about your products if done correctly.";
$str_similar = "I knows all of these repsesents a lot of informttion and it would take a often while to apply them all but the botom line is that marketiing is also important for growig your products ind achieve the business goals you&#8217;ve set out. Any actionable tactic will sure bring traffic to your website and grow the brand awareness about your products if done correctly.";
$str_similar = "Networking events represent also a wonderful way and a great place, to meet new candidates for the jobs you are promoting and draw attention to your product. A company booth, promotional goodies, and printed communication materials are one of the channels you can use to convey more information about your products and showcase the personality of your business.";
//$str_similar = "A brand (or marque for car model) is a name, term, design, symbol, or other feature that distinguishes an organization or product from its rivals in the eyes of the customer. Brands are used in business, marketing, and advertising. Branding is a set of marketing and communication methods that help to distinguish a company or [&hellip;]";
//$str1 = "Attending events can have several benefits and outcomes, it helps you build relationships with other individuals, exchange business cards and connect with other business owners in an informal environment. There, you will also get the chance to learn new things related to your industry and keep up-to-date with the latest trends,";
//$str_similar = "Attending events can have several benefits and outcomes, it really helps you build relationships with other individuals; do exchange business cards and connect with other business owners in an informal environment! There, you will also get the chances learning new things related to your industry and keep up-to-date with the latest trends,";
$percent = 0;
similar_text($str1, $str_similar, $percent );
echo '<br>similar_text = ' . $percent . '<br><br><br>';
echo '<br>' . array_sum(avg($str1)) . '<br>'. array_sum(avg($str_similar)) .'<br><br>';
echo '<br>====================================<br>';
//if ( array_sum(avg($str1)) < array_sum(avg($str_similar)) ){
$percent = array_sum(avg($str1)) * 100 / array_sum(avg($str_similar));
//} else {
// $percent = array_sum(avg($str_similar)) * 100 / array_sum(avg($str1));
//}
echo '<br>====================================<br>';
echo '<br>my own hash = ' . $percent . '<br><br><br>';
$j=0;
for($i=0; $i<10000; $i++){
$str2 = generateRandomString(360);
if ( array_sum(avg($str1)) < array_sum(avg($str2)) ){
$percent = array_sum(avg($str1)) * 100 / array_sum(avg($str2));
} else {
$percent = array_sum(avg($str2)) * 100 / array_sum(avg($str1));
}
if ($percent > 90){
$j++;
}
}
echo $j;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment