Shorten Code for Inserting Random Invisible Character

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 ^_*

< ?php // 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:
< ?php $data = "Quick brown fox jumps over the lazy dog!"; echo ghostText($data); ?>

Many thanks to Aryo for simplifying the function ^_*



Leave a Reply

Verified by MonsterInsights