Kaif Kaif - 1 year ago 70
PHP Question

deleting elements from array containing specific string keywords

i have an array $link which contains some links inside it and i wanna delete all the links which are from sites present in $Blocklinks



/* remove urls containing link from $Blocklinks .. What should i do here??*/

/* output */

output I want
[0] => http://ckfht.ca/sultan/files/2016/
[1] => http://dl1.uploadplus.net/dl2/2016/Sultan.2016/
[2] => http://www.google.com

Answer Source

If all you need is to filter urls by hostname, you can do it this way:

$result = array_filter($links, function ($i) use ($Blocklinks) {
    return !in_array(parse_url($i, PHP_URL_HOST), $Blocklinks); });