0

I have some link, lest say string

$string = "http://www.example.com/proizvodi/pokloni/kuhinja/?page=1";

I need new array $links

That will look like this

$links =array('proizvodi/','proizvodi/pokloni/', 'proizvodi/pokloni/kuhinja/');

I have tried

$crumbs = explode("/",$string]);

But the problem is that i dont need ?page=1 and first

Any idea, will be nice, txanks

1 Answer 1

3

If you're looking for just the breadcrumbs in path, do something like this:

$url = "http://www.example.com/proizvodi/pokloni/kuhinja/?page=1";

$decomposedURL = parse_url($url);
$crumbs = array_filter(explode("/", $decomposedURL['path'])); // array_filter to remove empty elements

UPDATE: What you want now is all the crumbs stacked over each other. Again, you can do that by the following code:

$links = [];
$lastString = "";
for($i=0;$i<count($crumbs);$i++) {
  $lastString += $crumbs[i]+"/";
  $links[] = $lastString;
}
Sign up to request clarification or add additional context in comments.

3 Comments

$crumbs = explode('/', parse_url($string, PHP_URL_PATH));
Txanks for now it is great but as i said i need more help, i am creating breadcrumbs based on your answer, only problem is that i have updated my question, can you please look
Also i got wrong array i have some empty first and last member Array ( [0] => [1] => proizvodi [2] => pokloni [3] => kuhinja [4] => )

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.