0

For example, if URL is http://localhost/category/news/old-stuff then this function gives me this result:

<a>newsold stuff</a>

Question:

how to put every word(s) between / to <a> tag ?

Example:

<a>news</a> <a>old stuff</a>

Function i am using:

$address =  $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$current = strtr($address, array('localhost' => '', 'category' => '', '/' => '', '-' => ' ' ));
echo '<a href="#">'. $current .'</a>';

Thanks for any answers and sorry for bad english.

Tauras
  • 3,846
  • 3
  • 21
  • 36
  • Possible duplicate of [PHP Simple dynamic breadcrumb](http://stackoverflow.com/questions/2594211/php-simple-dynamic-breadcrumb) – jhamon Mar 10 '16 at 15:09

2 Answers2

1

Try this :

$url =  $_SERVER['REQUEST_URI'];
$tags = explode('/', $url);
foreach ($tags as $tag) {
    echo "<a href='#'>" . str_replace('-',' ',$tag) . "</a> ";
}
Ravindra Bhalothia
  • 1,720
  • 2
  • 13
  • 16
1

You can use the following code:

$ex = explode("/",$_SERVER["REQUEST_URI"]);
foreach($ex as $val){
    echo '<a>'.str_replace('-',' ',$val).'</a>';
}
manish
  • 181
  • 1
  • 4