Search Results

Search found 3 results on 1 pages for 'achairapart'.

Page 1/1 | 1 

  • How to code an efficient blacklist filter function in php?

    - by achairapart
    So, I have three arrays like this: [items] => Array ( [0] => Array ( [id] => someid [title] => sometitle [author] => someauthor ... ) ... ) and also a string with comma separated words to blacklist: $blacklist = "some,words,to,blacklist"; Now I need to match these words with (as they can be one of) id, title, author and show results accordingly. I was thinking of a function like this: $pattern = '('.strtr($blacklist, ",", "|").')'; // should return (some|words|etc) foreach ($items as $item) { if ( !preg_match($pattern,$item['id']) || !preg_match($pattern,$item['title']) || !preg_match($pattern,$item['author']) ) { // show item } } and I wonder if this is the most efficient way to filter the arrays or I should use something with strpos() or filter_var with FILTER_VALIDATE_REGEXP ... Note that this function is repeated per 3 arrays. However, each array will not contain more than 50 items.

    Read the article

  • How reference popup object when opener page changes?

    - by achairapart
    This is driving me crazy! Scenario: The main page opens a pop-up window and later calls a function in it: newWin = window.open(someurl,'newWin',options); ...some code later... newWin.remoteFunction(options); and it's ok. Now, popup is still open and Main Page changes to Page 2. In Page 2 newWin doesn't exist anymore and I need to recreate the popup window object reference in order to call again the remote function (newWin.remoteFunction) I tried something like: newWin = open('','newWin', options); if (!newWin || newWin.closed || !newWin.remoteFunction) { newWin = window.open(someurl,'newWin',options); } And it works, I can call newWin.remoteFunction again BUT Safari for some reason gives Focus() to the popup window everytime the open() method is called breaking the navigation (I absolutely need the popup working in the background). Only workaround I can think to solve this is to create an interval in the popup with: if(window.opener && !window.opener.newWin) window.opener.newWin = self; and then set another interval in the opener Page with some try/catch but it is inelegant and very inefficient. so, I wonder, it's really so hard to get the popup object reference between different pages in the opener window?

    Read the article

1