-2

i have this array

    $array = array(
        "http://www.mywebsite.com/eternal_link_1",
        "http://www.mywebsite.com/eternal_link_2/",
        "http://www.mywebsite.com/eternal_link_1/#",
        "http://subdomain1.mywebwite.com",
        "http://subdomain2.mywebwite.com/eternal_link",
        "http://www.external-link.com"
    );

    $eternal_links = array();
    $subdomain_links = array();
    $external_links = array();

how i can filter $array and add the values to the 3 arrays above?

dev.bashar
  • 191
  • 1
  • 2
  • 14

1 Answers1

0

You can use strpos to find the correct string.

foreach($array as $item){

   if(strpos($item, 'external') == TRUE){
      array_push($external_links, $item);
   }

   // and go on..
}
Linesofcode
  • 5,327
  • 13
  • 62
  • 116
  • it's just example links, there is no 'external' word in the links – dev.bashar Feb 02 '15 at 16:58
  • @dev.bashar yes, that's taken, so adapt the example code provided to your own situation. This is an example you can use to reach the solution you want. Adapt its details . – Martin Feb 02 '15 at 17:00
  • Ohh, sorry for that. But, to know which ones are from a subdomain, you need to check for the domain..and you have the name of the domain or not? – Linesofcode Feb 02 '15 at 17:00
  • no i don't have the links, there is page php function read the links from html pages and i want to filter the results to this 3 arrays – dev.bashar Feb 02 '15 at 17:02
  • http://stackoverflow.com/questions/5292937/php-function-to-get-the-subdomain-of-a-url you can get if it's a subdomain or not from there. – Linesofcode Feb 02 '15 at 17:04