Page 1 of 1
How to exclude specific Urls from output?
Posted: Sun Sep 27, 2009 10:01 pm
by soul_fly
Many thanks to McInfo and Chris Corbyn's Regex Crash Course. At last I learnt how to grab urls from a webpage using preg_match.
The problem Now: I want to prune my output a bit. I got 60+ urls from a webpage like as follows:
http://devnetwork.com/hello.html
http://devnetwork.com/php.html
http://devnetwork.com/images/hello.jpg
so on....
During outputting results by print_r(), I just want to exclude all links that contains folder called images. (
http://devnetwork.com/images/*)
Hope that i'm clear

thx in advance for your co-operation.
Re: How to exclude specific Urls from output?
Posted: Sun Sep 27, 2009 10:07 pm
by requinix
If you create a function that can "reject" URLs then you can use
array_filter to remove bad URLs from your array.
(Could modify the regex but my opinion would be not to.)
Re: How to exclude specific Urls from output?
Posted: Sun Sep 27, 2009 10:10 pm
by soul_fly
tasairis wrote:If you create a function that can "reject" URLs then you can use
array_filter to remove bad URLs from your array.
(Could modify the regex but my opinion would be not to.)
I don't want to modify my regex either. Array filter is good idea. Thanks for your great hint.
My other folks, any other better idea, plz let me know also

Re: How to exclude specific Urls from output?
Posted: Mon Sep 28, 2009 3:24 am
by soul_fly
ok. I have read
http://php.net/manual/en/function.array-filter.php but couldn't figure out how to use array_filter() to exclude url from output.
The problem background:
$matches is the variable contains the results.
print_r($matches) <--- contains those 60+ Urls
I want to exclude all links contain
http://devnetwork.net/images/* from output.

Re: How to exclude specific Urls from output?
Posted: Mon Sep 28, 2009 12:29 pm
by soul_fly
knock knock. any volunteer to solve this prob?
Re: How to exclude specific Urls from output?
Posted: Mon Sep 28, 2009 3:18 pm
by requinix
tasairis wrote:If you create a function that can "reject" URLs
That was a hint. Have you created that function yet? It takes a URL as a string and returns true or false if the URL should be kept.
Re: How to exclude specific Urls from output?
Posted: Mon Sep 28, 2009 3:22 pm
by John Cartwright
To add to tasairis, you can specify a callback function to array_filter() to handle your "logic" and remove the appropriate array elements.
Re: How to exclude specific Urls from output?
Posted: Tue Sep 29, 2009 7:13 am
by mayanktalwar1988
hey u can do it like this
Code: Select all
<?
function url($var) {
if(strstr($var, "image"))
return false;
else
return true;
}
$array1 = array("www.dev.com/hello.php", "www.dev.com/image/hello.jpg","www.dev.com/image/mayank.jpg");
print_r(array_filter($array1, "url"));
?>