-1

I want to remove certain characters in a link. i.e.

'http://www.bbc.co.uk', strip everything and just be left with 'bbd'

At the moment i have the following:

$filteredFeed[$item->get_title()] =  array('title' => $item->get_title(), 'permalink' => $item->get_permalink(), 'date' => $item->get_date('G:i d-M-y'), 
    'url' =>$item->get_link());


      } 
endforeach;


foreach ($filteredFeed as $items) {

    echo '<li class="tips"><a href="' . $items['permalink'] . ' "target="_blank"">'; 
    echo  $items['title'];
    echo '</a>';
    echo '&nbsp;&nbsp;&nbsp;';
    echo '<span class="date">';
    echo $items['date'];
    echo '</span>';
    echo '&nbsp;&nbsp;&nbsp;';
    //echo $date;
    echo '</li>';



'url' =>$item->get_link()); - i get the link here.

How can i strip out the characters?

Miko
  • 109
  • 1
  • 7
  • 3
    I assume you want to be left with `'bbc'` in your example? What "certain" characters do you want to strip out? Does it *need* to be a regex. – gen_Eric Dec 29 '14 at 15:32
  • 2
    Have a look at the [`parse_url()`](http://php.net/manual/en/function.parse-url.php) function and/or [`explode()`](http://php.net/explode). – gen_Eric Dec 29 '14 at 15:37

1 Answers1

1
$url= 'http://www.bbc.co.uk';
$url = basename($url);
$url = str_replace('www.','',$url);
$url = preg_replace('/\.[^\.].*$/','',$url );

But this match always first subdomain exept www. TThen you may have interest to keep the basename.

toto21
  • 612
  • 5
  • 9