Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Dedicated server web hosting provided by Guru-host.eu.
Word in suspense (sus.ense) - plugin

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 419
Location: Kathmandu, Nepal

PostPosted: Sun Jul 04, 2010 8:59 pm    Post subject: Word in suspense (sus.ense) - plugin Reply with quote

Hiding details of a word is important sometimes. For example unauthenticated visitors of a service should not see the full details of a owner's name.

Inspired by google's behavior in hiding user names, I am publishing this code to suspense a word. It randomly replaces some letters of a word with a dot (.) making it somewhat harder to guess.

You may download modifier.suspense.php here

Code:
function smarty_modifier_suspense($word='')
{
   # suspense using this set of character(s)
   $suspense_character = '_';
   
   $letters = str_split($word, 1);
   
   if(count($letters) <= 2)
   {
      # Hide all characters when the total length is too small.
      foreach($letters as $l => $letter)
      {
         $letters[$l] = $suspense_character;
      }
   }
   else
   {
      foreach($letters as $l => $letter)
      {
         if($l%3==mt_rand(0, 2))
         {
            # Randomly hide some letters
            $letters[$l] = $suspense_character;
         }
      }
      
      # Make sure to suspense, even if mt_rand() genrated all zeros.
      $letters[1] = $suspense_character;
   }
   
   return implode('', $letters);
}


Usage examples
Code:
{$username|suspense}


if you take the below words to suspense:
Code:
$words = array(
   '',
   'a',
   'kp',
   'jil',
   'jack',
   'jackie',
   'william',
);


it will produce unpredictable set of word in return. Here are the samples:
= _
a = _
kp = __
jil = j_l
jack = ___k
jackie = j__kie
william = w___iam
_________________
Skype: pbimal
To hire instantly as a freelancer - https://www.odesk.com/o/profiles/users/_~~657b70cc7f2c616a/
Visit my website - http://bimal.org.np/ for more articles
800+ screenshots to learn about website mistakes: http://mistakes.sanjaal.com/
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP