Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Array filter regular expressions
    primarykey
    data
    text
    <p>Hi all i have an array shown below</p> <pre><code>Array ( [0] =&gt; http://api.tweetmeme.com/imagebutton.gif?url=http://mashable.com/2010/09/25/trailmeme/ [1] =&gt; http://cdn.mashable.com/wp-content/plugins/wp-digg-this/i/gbuzz-feed.png [2] =&gt; http://mashable.com/wp-content/plugins/wp-digg-this/i/fb.jpg [3] =&gt; http://mashable.com/wp-content/plugins/wp-digg-this/i/diggme.png [4] =&gt; http://ec.mashable.com/wp-content/uploads/2009/01/bizspark2.gif [5] =&gt; http://cdn.mashable.com/wp-content/uploads/2010/09/web.png [6] =&gt; http://mashable.com/wp-content/uploads/2010/09/Screen-shot-2010-09-24-at-10.51.26-PM.png [7] =&gt; http://cdn.mashable.com/wp-content/uploads/2009/02/bizspark.jpg [8] =&gt; http://feedads.g.doubleclick.net/~at/lxx00QTjYBaYojpnpnTa6MXUmh4/0/di [9] =&gt; [10] =&gt; http://feedads.g.doubleclick.net/~at/lxx00QTjYBaYojpnpnTa6MXUmh4/1/di [11] =&gt; [12] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=0N_mvMwPHYk:j5Pmi_N-JQ8:D7DqB2pKExk [13] =&gt; [14] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=0N_mvMwPHYk:j5Pmi_N-JQ8:V_sGLiPBpWU [15] =&gt; [16] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=0N_mvMwPHYk:j5Pmi_N-JQ8:F7zBnMyn0Lo [17] =&gt; [18] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=qj6IDK7rITs [19] =&gt; [20] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=_e0tkf89iUM [21] =&gt; [22] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=0N_mvMwPHYk:j5Pmi_N-JQ8:gIN9vFwOqvQ [23] =&gt; [24] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=yIl2AUoC8zA [25] =&gt; [26] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=P0ZAIrC63Ok [27] =&gt; [28] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=I9og5sOYxJI [29] =&gt; [30] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=CC-BsrAYo0A [31] =&gt; [32] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=0N_mvMwPHYk:j5Pmi_N-JQ8:_cyp7NeR2Rw [33] =&gt; [34] =&gt; http://feeds.feedburner.com/~r/Mashable/~4/0N_mvMwPHYk ) </code></pre> <p>basically, i want to </p> <ol> <li>remove every empty array element</li> <li>remove every array item without extensions <code>".jpg,.png,.gif"</code> in its name; </li> <li>finally remove array items containing keywords such as <code>"digg,fb,tweet,bizspark"</code>.</li> </ol> <hr> <p>have tried ur code and it returns eg hi, ive tried the above code... it returns an array containing the stuff i want out. </p> <p>hi, ive tried the above code... it returns an array containing the stuff i want out. )</p> <pre><code>Array ( [5] =&gt; http://feedads.g.doubleclick.net/~at/W-z_kHMi30EtE1mpxK8NvMmNmeg/0/di [7] =&gt; http://feedads.g.doubleclick.net/~at/W-z_kHMi30EtE1mpxK8NvMmNmeg/1/di [9] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=mEedXAp78pg:339cIishd6A:D7DqB2pKExk [11] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=mEedXAp78pg:339cIishd6A:V_sGLiPBpWU [13] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=mEedXAp78pg:339cIishd6A:F7zBnMyn0Lo [15] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=qj6IDK7rITs [17] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=_e0tkf89iUM [19] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=mEedXAp78pg:339cIishd6A:gIN9vFwOqvQ [21] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=yIl2AUoC8zA [23] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=P0ZAIrC63Ok [25] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=I9og5sOYxJI [27] =&gt; http://feeds.feedburner.com/~ff/Mashable?d=CC-BsrAYo0A [29] =&gt; http://feeds.feedburner.com/~ff/Mashable?i=mEedXAp78pg:339cIishd6A:_cyp7NeR2Rw [31] =&gt; http://feeds.feedburner.com/~r/Mashable/~4/mEedXAp78pg )) </code></pre> <p>)</p> <p>i would like it to return eg from first example</p> <pre><code>[5] =&gt; http://cdn.mashable.com/wp-content/uploads/2010/09/web.png [6] =&gt; http://mashable.com/wp-content/uploads/2010/09/Screen-shot-2010-09-24-at-10.51.26-PM.png </code></pre> <p>any ideas?</p> <hr> <p>Hi GZIp i have modified the code and im getting better results</p> <pre><code>function url_array_filter($url) { static $words = array('digg', 'fb', 'tweet', 'bizspark','feedburner','feedads','CountImage'); static $extens = array('.jpg', '.png', '.gif'); $ret = true; if (!$url) { $ret = false; } elseif (str_replace($words, '', $url) != $url) { $ret = false; } else { $path = parse_url($url, PHP_URL_PATH); if (in_array(substr($path, -4), $extens)) { $ret = false; } } return $ret; } </code></pre> <p>my problem now comes with the output. eg</p> <pre><code>Array ( [0] =&gt; http://cdn.dzone.com/images/thumbs/120x90/491551.jpg' style='width:120;height:90;float:left;vertical-align:top;border:1px solid ) Array ( [0] =&gt; http://cdn.dzone.com/images/thumbs/120x90/490913.jpg' style='width:120;height:90;float:left;vertical-align:top;border:1px solid ) </code></pre> <p>i want the url only. i think i have the problem with extracting urls from original content. lemme post a link to the origial question and what im doing.</p> <p><a href="https://stackoverflow.com/questions/3793768/rss-feeds-and-image-extraction-indepth">RSS Feeds and image extraction indepth</a></p> <p>i simply want the url. i think from that link.... getImagesUrl() maybe messing up. im going to try and use parse_url to bring back the correct url. lemme know if im on right track. im very close to manage pulling image urls from rss feeds parsed with magpie</p> <hr> <p>Ok GZip, this is the modification and addition ive added to ur code... 95% works!! great. although i do receive some funny results im posting below</p> <pre><code>function url_array_filter($url) { static $words = array('digg', 'fb', 'tweet', 'bizspark','feedburner','feedads','CountImage','fuelbrand'); static $extens = array('.jpg', '.png', '.gif'); $ret = true; if (!$url) { $ret = false; } elseif (str_replace($words, '', $url) != $url) { $ret = false; } else { $path = parse_url($url, PHP_URL_PATH); if (in_array(substr($path, -4), $extens)) { $ret = false; } } return $ret; } function cleanURL($a_url) { $ret=array(); foreach ($a_url as $c) { $a=parse_url($c, PHP_URL_SCHEME).'://'.parse_url($c, PHP_URL_HOST).parse_url($c, PHP_URL_PATH); $a=explode("'",$a); $ret[]=$a[0]; } return $ret; } </code></pre> <p>example usage. $this->getImagesUrl($c); below returns results in first question.</p> <pre><code> foreach($content as $c) { // get the images in content $arr = $this-&gt;getImagesUrl($c); $arr = array_filter($arr, 'url_array_filter'); } $ret=cleanURL($arr); if (count($ret)&gt;0) { print_r($ret); echo "&lt;br/&gt;&lt;br/&gt;"; } </code></pre> <p>up to this point almost everything works great but i keep getting some bad results like</p> <pre><code>Array ( [0] =&gt; http://cdn.mashable.com/wp-content/uploads/2010/02/ipad-side- ) Array ( [0] =&gt; http://mrg.bz/FZtr2k [1] =&gt; http://mrg.bz/IDkx4w ) </code></pre> <p>people we almost there... any ideas</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload