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 🙂

Life without an Anti Virus

If you have a virus or a trojan running around on your machine it is most likely you yourself are the source of the infection. Only on very rare auctions a hostile program can infiltrate into your operating system all on it’s own, meaning that if you got infected you took an active part somewhere in the process of the infection. It may have been that USB Flash Drive you got from friend and connected to your machine, maybe you downloaded some pirated software that packed some unwanted additions or maybe it was that adult website that asked for you permission to install some Add On that will allow you to watch some of it’s video.

After realizing a while ago, about when windows 95 was still around, I decided to stop using an anti virus software on a regular basis because it takes a lot of computer resources thus slowing down the machine. I do install an anti virus program once a year or so and scan my machine to make sure nothing got by me, I prefer to use Avast anti virus which doesn’t embed itself into Windows and offers a pre-boot scan.

I’m usually not too concerned about viruses/worms/etc but every once in while a computer security guy needs to download and install some shady program from some shady website. Which lead me to writing this post, postponing my decision whether to download or not a 100% clean virus free copy of IDA Pro 6.