Blog

The Revenge of Bottomembly

A few days ago I was out walking and reminiscing, as I am wont to do. While I was doing this, I recalled some of my first web related programming projects, most notably YPNgine. Considering it was my first major PHP outing, I pulled off quite a feat. Writing a message board is no small task. However, there was one part in particular that I was mulling over: the censor.

If you happen to be a former YPNer, you may recall seeing many references to "bottomembly". Carrying over the censor find/replace list that had been used on phpBB before it, all instances of the character sequence "ass" were summarily replaced with "bottom". Now I am being very choosy when I say "character sequence" and not "word" as the censor couldn't differentiate words.

This oversight was brought to my attention my young programmer self struggled to figure out a solution. Here's what I wound up doing:

Code: php
  1. // Copyright (c) 2003 Matt Hackmann
  2. // Full copyright info in index.php
  3. function censor_post ($body)
  4. {
  5. $query = "SELECT * FROM bannedwords";
  6. $result = db_Query ($query);
  7. $body = " ".$body;
  8. $body = str_ireplace ("assembly", "ytrewq", $body);
  9. $body = str_ireplace ("assum", "asd;ljf", $body);
  10. $body = str_ireplace ("glass", "glss", $body);
  11. $body = str_ireplace ("hello", "hllo", $body);
  12. for ($i = 0; $i < db_num_Rows ($result); $i++) {
  13. $row = db_fetch_array ($result);
  14. $body = str_ireplace ($row["blocked_word"], "", $body);
  15. }
  16. if ($body == " ")
  17. $body = "Censored";
  18. $body = str_replace ("asd;ljf", "assum", $body);
  19. $body = str_replace ("ytrewq", "assembly", $body);
  20. $body = str_replace ("glss", "glass", $body);
  21. $body = str_ireplace ("hllo", "hello", $body);
  22. return $body;
  23. }
  24. ?>

As you can see, I started hard coding in a list of safe words, replacing those instances with a random (or not so random) string of characters, run the censor and then convert those strings back to the safe words. This was a list I kept expanding on as they were found during normal conversation on the forum. I giggle as I look at this list and think of what the censor was doing to those words: bottomume, glbottom and hecko.

It's just something that I, eight years later, have to look back on and chuckle about.

Post A Comment

AvatarLogin with FacebookLogin with Twitter