PDA

View Full Version : Miscellaneous Hacks - Replace threadpost characters


kenfuzed
04-10-2007, 10:00 PM
Recently I was in search of a way to replace or restrict the use of non-alpha characters used in thread titles. This is useful when adding your thread titles to a welcome header or other area where these characters would look out of place (i.e. '!' or '?' placed mid sentence).

The following is a manual addition of code which will replace specified characters with whatever you want.

Start by finding /includes/class_dm_threadpost.php
You may want to make a backup copy of this file in case you blow things up :eek:

Open class_dm_threadpost.php in an editor and find the following code:

// replace html-encoded spaces with actual spaces
$title = preg_replace('/&#(0*32|x0*20);/', ' ', $title);

If you only want to replace the characters '?' and '!' with a space, then below the above code you would add:
$title = preg_replace('/[\?\!]/', ' ', $title);

NOTE: DO NOT delete or change the first piece of code. It is there to prevent html from being added to thread titles. Add all additional code under it.

Between the [brackets] only add the characters you wish to have replaced when a user types it into their thread title. Separate each character with a backslash.

I personally didn't want to see anything except alpha-numeric titles so I included just about every character. The first part replaces the specified character with a space. The next part I added replaces each specific character with a corresponding word (i.e. '&' is replaced by the word 'and').
Below:
// replace html-encoded spaces with actual spaces
$title = preg_replace('/&#(0*32|x0*20);/', ' ', $title);

I added:
// replace special characters with actual spaces
$title = preg_replace('/[\?\!\#\$\%\^\*\~\|\:\;\...]/', ' ', $title);
// replace special characters with...
$title = preg_replace('/[\@]/', ' at ', $title);
$title = preg_replace('/[\+]/', ' plus ', $title);
$title = preg_replace('/[\=]/', ' equals ', $title);
$title = preg_replace('/[\&]/', ' and ', $title);

Special thanks to Oleg for helping me locate where to find this file/code.

Hornstar
04-12-2007, 12:58 AM
Nice work, i think i may leave this for now tho. dont feel like editing any core files currently lol

gforce75
08-01-2007, 11:55 AM
Good Concept. Thanks.

caggla
07-10-2008, 02:07 PM
works on 3.7.
thanks