tags:

views:

37

answers:

2

I am not able to find a code to filter this in PHP..

I do have multiple urls for example :

www.google.com
www.twiter.com
www.facebook.com
www.youtube.com
www.techcrunch.com/webroot-brightcloud/
www.mashable.com/hello-how-are-you/
www.yahoo.com
www.msn.com

what I want is I need to filter domains with sub directories or pages. here in example techcrunch.com and mashable.com need to remove from final list as they do have sub pages.

The above is an example so any domains with sub pages or sub directories need to be remove from list.

How do we do it in PHP

Any Ideas??

+1  A: 
array_filter($arr, function ($el) { return strpos($el, "/") === false; });

Or for versions < PHP 5.3:

function sel($el) {
    return strpos($el, "/") === false;
}
$res = array_filter($arr, 'sel');
Artefacto
Actually I want to remove such URLS from current list...
mathew
@mat That's what this does. See http://codepad.viper-7.com/EWPisK
Artefacto
@Artefacto oh very good you are great....thanks man.
mathew
A: 

If the mere existence of a forward slash is all you need to filter, then go with Artefacto's answer. If you need to be able to deal with less predictable formats, you can use parse_url:

$url = 'www.techcrunch.com/?a=asd/zxc';
$urlInfo = parse_url("http://$url");
if (strlen(trim($urlInfo['path'], '/'))) {
    // remove from list
}
webbiedave