Shorten Code for Inserting Random Invisible Character

December 13, 2006 | PHP

This post is related correction to my previous one, inserting invisible random character inbetween words to avoid copy-paste doer.

I wrote a function to insert invisible random character inbetween words, and it used looped str_replace() to seek for the whitespaces. And I realize it’s not good for a very long texts, because the process will slowed down. So here is a new function with call back method, hopefully it will be faster and cooler ^_*

// main function, will call the replacews() function
function ghostText($data){
return preg_replace_callback('{((\s)+?)}i', "replacews", $data);
}
function replacews($xxx){
$c = chr(mt_rand(62,155));
return "$c";
}
?>

And the usage is still quite simple:
$data = "Quick brown fox jumps over the lazy dog!";
echo ghostText($data);
?>

Many thanks to Aryo for simplifying the function ^_*

 

No comment

This post has no comments, you can be the first!

 

Leave a comment

Allowed tags are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


 



Switch to our mobile site