Strip/Remove IRC client control characters

Here’s a small PHP function that gets rid of the mIRC (or any other IRC client) control characters, that is the colors, underlines, italics, etc.

function stripControlCharacters($text) {
	$controlCodes = array(
		'/(\x03(?:\d{1,2}(?:,\d{1,2})?)?)/',	// Color code
		'/\x02/',								// Bold
		'/\x0F/',								// Escaped
		'/\x16/',								// Italic
		'/\x1F/'								// Underline
	);
	return preg_replace($controlCodes,'',$text);
}

PHP – Collapse multiple line drops to a single line drop

If you need to clean up some input by removing multiple new line drops and replace it with a single new line drop, for example, making this piece of text:

Lorem ipsum dolor sit amet,

consectetur adipiscing elit.
 

Aliquam ac elit at elit viverra mollis.

Cras tincidunt leo eleifend purus fermentum.

Look like this:

Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
Aliquam ac elit at elit viverra mollis.
Cras tincidunt leo eleifend purus fermentum.

The following PHP function will remove the consecutive new line characters.

function collapseNewLines($str) {
	return  preg_replace('/((\r?)\n)+/', "\n", $str);
}

Windows/DOS new line is represented by the two characters \r\n and UNIX like systems use only the single char \n . The function handle both cases.
If you find it useful, a link to this blog would be nice 🙂

Free QDB System

Are you an IRC dweller? Got your own channel? Are you looking for an easy way to collect quotes of you and your friends mucking around? You also want to let your friends rate them, comment and share on social networks? Well, you can stop looking, all you need is an iBash account from. Once you create one, you can setup as many quotes collections as you want. Check out the cool design of a collection and it’s URL: http://www.iBash.org/Bash