felipeNascimento.org(true);

Making the web a better place to live

Browsing Posts published in December, 2009

PHPClasses nomnee

No comments

Hey folks.
My PHP Class OFXParser is running to become one of the winers of the best 12 classes at PHPclasses.org.
Those who have interest, please, vote.
OFX is a XML based format for exchanging financial records between programs that manipulate this kind of information, like Intuit Quicken, Microsoft Money, Google Finance, etc..
This class provides a PHP solution to extract financial records from OFX files and also offering you a lot of methods to deal with these data.

To vote, visit: PHP Classes vote page

Well, we know how to remove an item from any Array in Javascript by using the splice method, but some times we want to remove an item by its value, not by its position.
The aparent solution is to run over the whole array and then find the element that maches with the value we want.
I prepared this small function in JavaScript to remove any item from a given Array by its value using a very optimized way with regular expressions. Notice that using regular expression was an option. Regular expression is a little bit heavier than running through the array using a extremely optimized “for”, then, it’s faster. Although, here goes this on line option to do this:

function removeItem(ar, item)
{
    return ar.join(';').
             replace(new RegExp("(^|;)"+item+"(;|$)"), ';').
             replace(/(^;)|(;$)/g, '').
             split(';');
}

This function is an one line function which returns the array already without the item that had the specified value.

I hope it helps you.