Tips.PHP: Removing empty strings, NULL, FALSE, and negative numbers from Array

Often we need to remove empty elements from our array. For example when we split a string with space, we can get the words and also blank strings when there are two or more spaces put together. We can use array_filter function for rescue. When we call array_filter with out passing the filter function it removes all values that evaluate to FALSE. <?php $string = "I love   Luracast...

Read More

Tips.PHP: Securing ViewSource.php

I’m in the process of creating Usage examples for the brand new version of RESTler. Take a look at the work in progress version here (I would love to hear your thoughts). One of the nice features in that is the ability to see the source code. I’m using a getsource.php which will return the source code of any php file when the relative path is passed as a query parameter. It is...

Read More

Removing Byte Order Mark (BOM) from the given string.

Since PHP does not recognize and ignore BOM in the loaded files, I wrote the following script to find and remove the BOM from the loaded string. function removeBOM($str=''){     if(<a href="http://www.php.net/strpos">strpos</a>($str, "»")==1)$str=<a...

Read More