Question

I want to strip the Host and Path elements from the "URL" in an array using a foreach loop.

I am doing this as I am comparing results from different search engines and currently very few are "matching" due to slight difference with how search engines handle sites Url's.

I have read the PHP manual site, tried googling it and read many of the questions already asked on Stackoverflow but can not find an example dealing with stripping elements within an array within a foreach loop and then rebuilding them.

I was hoping to use something like this:

{$url0 =  parse_url($url, PHP_URL_HOST);
$url1 =  parse_url($url, PHP_URL_PATH);
$url = "$url0$url1";}

// With the foreach loop

 foreach ($jsonObj->d->results as $value) {
   $resultsB[] = array(
     'url' => strip_tags($value->Url),
     'url' => $value->Url,
     'title' => $value->Title,
     'rank' => $i--,
     'desc' => $value->Description,
     $b++,
  );
}

Any help on this or any other method to increase the accuracy of my matching process would be very much appreciated.

No correct solution

OTHER TIPS

 foreach ($jsonObj->d->results as $value) {

    // Leave only host + path
    $url = strip_tags($value->Url);
    $url = $url['host'] . $url['path'];

    $resultsB[] = array(
        'url' => $url,
        'title' => $value->Title,
        'rank' => $i--,
        'desc' => $value->Description,
        $b++,
  );
}

Something like this?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top